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년 전 조회 691
14년 전 조회 677
14년 전 조회 1,462
14년 전 조회 1,272
14년 전 조회 2,354
14년 전 조회 1,272
14년 전 조회 869
14년 전 조회 3,389
14년 전 조회 1,613
14년 전 조회 1,024
14년 전 조회 1,387
14년 전 조회 746
14년 전 조회 1,867
14년 전 조회 795
14년 전 조회 1,231
14년 전 조회 741
14년 전 조회 1,273
14년 전 조회 1,509
14년 전 조회 1,018
14년 전 조회 804
14년 전 조회 1,018
14년 전 조회 960
14년 전 조회 1,972
14년 전 조회 1,140
14년 전 조회 843
14년 전 조회 740
14년 전 조회 1,353
14년 전 조회 2,645
14년 전 조회 735
14년 전 조회 2,564
14년 전 조회 1,678
14년 전 조회 911
14년 전 조회 1,133
14년 전 조회 1,021
14년 전 조회 1,014
14년 전 조회 534
14년 전 조회 740
14년 전 조회 843
14년 전 조회 1,203
14년 전 조회 904
14년 전 조회 1,261
14년 전 조회 1,043
14년 전 조회 1,144
14년 전 조회 744
14년 전 조회 1,058
14년 전 조회 956
14년 전 조회 828
14년 전 조회 718
14년 전 조회 1,207
14년 전 조회 1,617
14년 전 조회 971
14년 전 조회 808
14년 전 조회 3,340
14년 전 조회 868
14년 전 조회 743
14년 전 조회 2,138
14년 전 조회 1,541
14년 전 조회 2,059
14년 전 조회 621
14년 전 조회 878
14년 전 조회 729
14년 전 조회 570
14년 전 조회 654
14년 전 조회 782
14년 전 조회 1,524
14년 전 조회 887
14년 전 조회 938
14년 전 조회 555
14년 전 조회 1,086
14년 전 조회 1,678
14년 전 조회 1,068
14년 전 조회 1,354
14년 전 조회 870
14년 전 조회 1,008
14년 전 조회 799
14년 전 조회 1,123
14년 전 조회 1,026
14년 전 조회 445
14년 전 조회 579
14년 전 조회 656
14년 전 조회 965
14년 전 조회 788
14년 전 조회 792
14년 전 조회 771
14년 전 조회 1,176
14년 전 조회 880
14년 전 조회 887
14년 전 조회 895
14년 전 조회 704
14년 전 조회 1,760
14년 전 조회 1,535
14년 전 조회 961
14년 전 조회 789
14년 전 조회 1,857
14년 전 조회 1,227
14년 전 조회 1,061
14년 전 조회 822
14년 전 조회 1,524
14년 전 조회 3,789
14년 전 조회 2,446
🐛 버그신고