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년 전 조회 797
14년 전 조회 769
14년 전 조회 1,553
14년 전 조회 1,365
14년 전 조회 2,434
14년 전 조회 1,358
14년 전 조회 959
14년 전 조회 3,485
14년 전 조회 1,695
14년 전 조회 1,120
14년 전 조회 1,487
14년 전 조회 838
14년 전 조회 1,973
14년 전 조회 913
14년 전 조회 1,338
14년 전 조회 841
14년 전 조회 1,362
14년 전 조회 1,604
14년 전 조회 1,123
14년 전 조회 908
14년 전 조회 1,129
14년 전 조회 1,024
14년 전 조회 2,067
14년 전 조회 1,245
14년 전 조회 934
14년 전 조회 843
14년 전 조회 1,445
14년 전 조회 2,731
14년 전 조회 837
14년 전 조회 2,660
14년 전 조회 1,778
14년 전 조회 1,004
14년 전 조회 1,230
14년 전 조회 1,122
14년 전 조회 1,110
14년 전 조회 634
14년 전 조회 833
14년 전 조회 935
14년 전 조회 1,312
14년 전 조회 1,001
14년 전 조회 1,366
14년 전 조회 1,127
14년 전 조회 1,238
14년 전 조회 845
14년 전 조회 1,142
14년 전 조회 1,061
14년 전 조회 927
14년 전 조회 824
14년 전 조회 1,292
14년 전 조회 1,701
14년 전 조회 1,075
14년 전 조회 909
14년 전 조회 3,444
14년 전 조회 969
14년 전 조회 848
14년 전 조회 2,226
14년 전 조회 1,639
14년 전 조회 2,155
14년 전 조회 712
14년 전 조회 963
14년 전 조회 813
14년 전 조회 648
14년 전 조회 754
14년 전 조회 868
14년 전 조회 1,617
14년 전 조회 965
14년 전 조회 1,038
14년 전 조회 645
14년 전 조회 1,189
14년 전 조회 1,771
14년 전 조회 1,165
14년 전 조회 1,440
14년 전 조회 953
14년 전 조회 1,104
14년 전 조회 898
14년 전 조회 1,221
14년 전 조회 1,113
14년 전 조회 539
14년 전 조회 679
14년 전 조회 733
14년 전 조회 1,063
14년 전 조회 890
14년 전 조회 894
14년 전 조회 861
14년 전 조회 1,274
14년 전 조회 978
14년 전 조회 980
14년 전 조회 988
14년 전 조회 804
14년 전 조회 1,854
14년 전 조회 1,632
14년 전 조회 1,053
14년 전 조회 887
14년 전 조회 1,956
14년 전 조회 1,324
14년 전 조회 1,161
14년 전 조회 918
14년 전 조회 1,625
14년 전 조회 3,884
14년 전 조회 2,535