subquery 전문가 함 보세요

select *  from c_deal where de_mb_id='admin' and de_t='5' and de_jo_name = (select  de_jo_name   FROM c_deal WHERE `de_mb_id` ='admin'  AND `de_t` ='5' group by de_jo_name having sum(de_qtyB)-sum(de_qtyS) < 1 )
 
요러면 원하는 리스트 나오는데
요걸
 
delete  from c_deal where de_mb_id='admin' and de_t='5' and de_jo_name = (select  de_jo_name   FROM c_deal WHERE `de_mb_id` ='admin'  AND `de_t` ='5' group by de_jo_name having sum(de_qtyB)-sum(de_qtyS) < 1 )
하면
 
MySQL 메시지: 
#1093 - You can't specify target table 'c_deal' for update in FROM clause
 
게 되는 이유 아시는분 ....

 
|

댓글 3개

상황별로 어떤지 모르겠네요. 일단 스키마랑 샘플 데이타를 올려주시면 좀더 명확하게 체크 될것 같네요.

체크해봐야 할 부분
1. delete 조건절에 subquery 가능 여부와 subquery 에 group by, having 가능 여부
- select 랑 delete랑 다를수 있음..
2. select 에 max를 써봄
3. de_jo_name = 을 de_jo_name in 조건으로 변경해봄
자기 자신을 참조하여 insert,update,delete 할경우.. 발생하는 오류입니다.
해당 서브쿼리를 한번 더 감싸주시면 됩니당..


DELETE from c_deal
WHERE de_mb_id='admin'
AND de_t='5'
AND de_jo_name = (select T1.de_jo_name
from ( select de_jo_name
from c_deal
where `de_mb_id` ='admin'
and `de_t` ='5'
group by de_jo_name
having sum(de_qtyB)-sum(de_qtyS) < 1) T1)
요런식으로...
감솨해요....
댓글을 작성하시려면 로그인이 필요합니다.

프로그램

+
제목 글쓴이 날짜 조회
14년 전 조회 1,452
14년 전 조회 1,446
14년 전 조회 2,226
14년 전 조회 2,014
14년 전 조회 3,021
14년 전 조회 2,005
14년 전 조회 1,616
14년 전 조회 4,152
14년 전 조회 2,332
14년 전 조회 1,771
14년 전 조회 2,123
14년 전 조회 1,476
14년 전 조회 2,644
14년 전 조회 1,527
14년 전 조회 1,967
14년 전 조회 1,485
14년 전 조회 1,993
14년 전 조회 2,240
14년 전 조회 1,754
14년 전 조회 1,531
14년 전 조회 1,784
14년 전 조회 1,651
14년 전 조회 2,703
14년 전 조회 1,864
14년 전 조회 1,572
14년 전 조회 1,479
14년 전 조회 2,097
14년 전 조회 3,362
14년 전 조회 1,483
14년 전 조회 3,316
14년 전 조회 2,444
14년 전 조회 1,637
14년 전 조회 1,845
14년 전 조회 1,756
14년 전 조회 1,741
14년 전 조회 1,267
14년 전 조회 1,456
14년 전 조회 1,569
14년 전 조회 1,927
14년 전 조회 1,617
14년 전 조회 1,980
14년 전 조회 1,764
14년 전 조회 1,919
14년 전 조회 1,518
14년 전 조회 1,788
14년 전 조회 1,705
14년 전 조회 1,583
14년 전 조회 1,469
14년 전 조회 1,907
14년 전 조회 2,315
14년 전 조회 1,714
14년 전 조회 1,530
14년 전 조회 4,065
14년 전 조회 1,598
14년 전 조회 1,484
14년 전 조회 2,833
14년 전 조회 2,266
14년 전 조회 2,781
14년 전 조회 1,343
14년 전 조회 1,583
14년 전 조회 1,397
14년 전 조회 1,258
14년 전 조회 1,357
14년 전 조회 1,472
14년 전 조회 2,229
14년 전 조회 1,572
14년 전 조회 1,650
14년 전 조회 1,272
14년 전 조회 1,768
14년 전 조회 2,386
14년 전 조회 1,784
14년 전 조회 2,060
14년 전 조회 1,560
14년 전 조회 1,700
14년 전 조회 1,505
14년 전 조회 1,834
14년 전 조회 1,712
14년 전 조회 1,135
14년 전 조회 1,313
14년 전 조회 1,313
14년 전 조회 1,653
14년 전 조회 1,489
14년 전 조회 1,521
14년 전 조회 1,449
14년 전 조회 1,857
14년 전 조회 1,578
14년 전 조회 1,573
14년 전 조회 1,590
14년 전 조회 1,394
14년 전 조회 2,432
14년 전 조회 2,217
14년 전 조회 1,639
14년 전 조회 1,473
14년 전 조회 2,545
14년 전 조회 1,897
14년 전 조회 1,732
14년 전 조회 1,465
14년 전 조회 2,174
14년 전 조회 4,459
14년 전 조회 3,087