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년 전 조회 698
14년 전 조회 685
14년 전 조회 1,467
14년 전 조회 1,282
14년 전 조회 2,360
14년 전 조회 1,280
14년 전 조회 874
14년 전 조회 3,401
14년 전 조회 1,620
14년 전 조회 1,035
14년 전 조회 1,395
14년 전 조회 757
14년 전 조회 1,878
14년 전 조회 802
14년 전 조회 1,237
14년 전 조회 751
14년 전 조회 1,283
14년 전 조회 1,521
14년 전 조회 1,029
14년 전 조회 811
14년 전 조회 1,030
14년 전 조회 966
14년 전 조회 1,983
14년 전 조회 1,151
14년 전 조회 848
14년 전 조회 749
14년 전 조회 1,358
14년 전 조회 2,654
14년 전 조회 743
14년 전 조회 2,571
14년 전 조회 1,688
14년 전 조회 920
14년 전 조회 1,144
14년 전 조회 1,031
14년 전 조회 1,016
14년 전 조회 544
14년 전 조회 748
14년 전 조회 852
14년 전 조회 1,213
14년 전 조회 915
14년 전 조회 1,270
14년 전 조회 1,053
14년 전 조회 1,153
14년 전 조회 753
14년 전 조회 1,063
14년 전 조회 965
14년 전 조회 839
14년 전 조회 728
14년 전 조회 1,213
14년 전 조회 1,624
14년 전 조회 977
14년 전 조회 820
14년 전 조회 3,346
14년 전 조회 874
14년 전 조회 754
14년 전 조회 2,144
14년 전 조회 1,549
14년 전 조회 2,071
14년 전 조회 628
14년 전 조회 886
14년 전 조회 736
14년 전 조회 575
14년 전 조회 661
14년 전 조회 787
14년 전 조회 1,533
14년 전 조회 893
14년 전 조회 948
14년 전 조회 563
14년 전 조회 1,096
14년 전 조회 1,684
14년 전 조회 1,073
14년 전 조회 1,360
14년 전 조회 881
14년 전 조회 1,015
14년 전 조회 808
14년 전 조회 1,129
14년 전 조회 1,029
14년 전 조회 452
14년 전 조회 589
14년 전 조회 661
14년 전 조회 972
14년 전 조회 796
14년 전 조회 797
14년 전 조회 776
14년 전 조회 1,183
14년 전 조회 890
14년 전 조회 892
14년 전 조회 901
14년 전 조회 713
14년 전 조회 1,771
14년 전 조회 1,541
14년 전 조회 966
14년 전 조회 792
14년 전 조회 1,867
14년 전 조회 1,231
14년 전 조회 1,064
14년 전 조회 830
14년 전 조회 1,532
14년 전 조회 3,794
14년 전 조회 2,455