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년 전 조회 663
14년 전 조회 641
14년 전 조회 1,433
14년 전 조회 1,244
14년 전 조회 2,340
14년 전 조회 1,243
14년 전 조회 841
14년 전 조회 3,356
14년 전 조회 1,582
14년 전 조회 997
14년 전 조회 1,357
14년 전 조회 717
14년 전 조회 1,837
14년 전 조회 768
14년 전 조회 1,203
14년 전 조회 710
14년 전 조회 1,241
14년 전 조회 1,476
14년 전 조회 986
14년 전 조회 772
14년 전 조회 992
14년 전 조회 924
14년 전 조회 1,943
14년 전 조회 1,113
14년 전 조회 816
14년 전 조회 713
14년 전 조회 1,323
14년 전 조회 2,612
14년 전 조회 705
14년 전 조회 2,535
14년 전 조회 1,651
14년 전 조회 882
14년 전 조회 1,096
14년 전 조회 991
14년 전 조회 984
14년 전 조회 502
14년 전 조회 709
14년 전 조회 811
14년 전 조회 1,175
14년 전 조회 869
14년 전 조회 1,229
14년 전 조회 1,012
14년 전 조회 1,112
14년 전 조회 714
14년 전 조회 1,022
14년 전 조회 919
14년 전 조회 795
14년 전 조회 688
14년 전 조회 1,173
14년 전 조회 1,583
14년 전 조회 936
14년 전 조회 775
14년 전 조회 3,307
14년 전 조회 834
14년 전 조회 716
14년 전 조회 2,108
14년 전 조회 1,504
14년 전 조회 2,024
14년 전 조회 591
14년 전 조회 842
14년 전 조회 698
14년 전 조회 538
14년 전 조회 623
14년 전 조회 750
14년 전 조회 1,497
14년 전 조회 857
14년 전 조회 905
14년 전 조회 529
14년 전 조회 1,059
14년 전 조회 1,649
14년 전 조회 1,039
14년 전 조회 1,328
14년 전 조회 842
14년 전 조회 972
14년 전 조회 765
14년 전 조회 1,094
14년 전 조회 996
14년 전 조회 415
14년 전 조회 550
14년 전 조회 626
14년 전 조회 938
14년 전 조회 762
14년 전 조회 758
14년 전 조회 744
14년 전 조회 1,151
14년 전 조회 850
14년 전 조회 858
14년 전 조회 869
14년 전 조회 675
14년 전 조회 1,735
14년 전 조회 1,503
14년 전 조회 932
14년 전 조회 758
14년 전 조회 1,830
14년 전 조회 1,195
14년 전 조회 1,035
14년 전 조회 793
14년 전 조회 1,499
14년 전 조회 3,758
14년 전 조회 2,416
🐛 버그신고