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년 전 조회 814
14년 전 조회 789
14년 전 조회 1,582
14년 전 조회 1,385
14년 전 조회 2,450
14년 전 조회 1,380
14년 전 조회 982
14년 전 조회 3,512
14년 전 조회 1,725
14년 전 조회 1,138
14년 전 조회 1,512
14년 전 조회 856
14년 전 조회 2,001
14년 전 조회 938
14년 전 조회 1,357
14년 전 조회 867
14년 전 조회 1,378
14년 전 조회 1,632
14년 전 조회 1,142
14년 전 조회 921
14년 전 조회 1,149
14년 전 조회 1,046
14년 전 조회 2,081
14년 전 조회 1,261
14년 전 조회 944
14년 전 조회 865
14년 전 조회 1,468
14년 전 조회 2,752
14년 전 조회 858
14년 전 조회 2,673
14년 전 조회 1,810
14년 전 조회 1,025
14년 전 조회 1,247
14년 전 조회 1,136
14년 전 조회 1,126
14년 전 조회 661
14년 전 조회 853
14년 전 조회 959
14년 전 조회 1,323
14년 전 조회 1,019
14년 전 조회 1,384
14년 전 조회 1,143
14년 전 조회 1,269
14년 전 조회 880
14년 전 조회 1,164
14년 전 조회 1,079
14년 전 조회 950
14년 전 조회 849
14년 전 조회 1,315
14년 전 조회 1,721
14년 전 조회 1,102
14년 전 조회 926
14년 전 조회 3,465
14년 전 조회 991
14년 전 조회 867
14년 전 조회 2,244
14년 전 조회 1,653
14년 전 조회 2,176
14년 전 조회 728
14년 전 조회 993
14년 전 조회 827
14년 전 조회 667
14년 전 조회 770
14년 전 조회 886
14년 전 조회 1,632
14년 전 조회 994
14년 전 조회 1,063
14년 전 조회 664
14년 전 조회 1,209
14년 전 조회 1,798
14년 전 조회 1,187
14년 전 조회 1,467
14년 전 조회 973
14년 전 조회 1,123
14년 전 조회 917
14년 전 조회 1,244
14년 전 조회 1,134
14년 전 조회 557
14년 전 조회 708
14년 전 조회 756
14년 전 조회 1,082
14년 전 조회 908
14년 전 조회 916
14년 전 조회 886
14년 전 조회 1,299
14년 전 조회 996
14년 전 조회 1,003
14년 전 조회 1,029
14년 전 조회 830
14년 전 조회 1,875
14년 전 조회 1,655
14년 전 조회 1,076
14년 전 조회 913
14년 전 조회 1,979
14년 전 조회 1,344
14년 전 조회 1,180
14년 전 조회 938
14년 전 조회 1,642
14년 전 조회 3,905
14년 전 조회 2,559