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년 전 조회 681
14년 전 조회 659
14년 전 조회 1,449
14년 전 조회 1,262
14년 전 조회 2,346
14년 전 조회 1,259
14년 전 조회 857
14년 전 조회 3,374
14년 전 조회 1,599
14년 전 조회 1,012
14년 전 조회 1,373
14년 전 조회 731
14년 전 조회 1,856
14년 전 조회 785
14년 전 조회 1,219
14년 전 조회 726
14년 전 조회 1,258
14년 전 조회 1,495
14년 전 조회 1,005
14년 전 조회 789
14년 전 조회 1,010
14년 전 조회 941
14년 전 조회 1,963
14년 전 조회 1,130
14년 전 조회 831
14년 전 조회 730
14년 전 조회 1,342
14년 전 조회 2,630
14년 전 조회 723
14년 전 조회 2,550
14년 전 조회 1,667
14년 전 조회 900
14년 전 조회 1,118
14년 전 조회 1,012
14년 전 조회 1,002
14년 전 조회 520
14년 전 조회 729
14년 전 조회 831
14년 전 조회 1,193
14년 전 조회 886
14년 전 조회 1,247
14년 전 조회 1,030
14년 전 조회 1,132
14년 전 조회 735
14년 전 조회 1,042
14년 전 조회 940
14년 전 조회 815
14년 전 조회 707
14년 전 조회 1,191
14년 전 조회 1,601
14년 전 조회 954
14년 전 조회 797
14년 전 조회 3,330
14년 전 조회 851
14년 전 조회 733
14년 전 조회 2,127
14년 전 조회 1,528
14년 전 조회 2,044
14년 전 조회 612
14년 전 조회 865
14년 전 조회 715
14년 전 조회 554
14년 전 조회 642
14년 전 조회 769
14년 전 조회 1,513
14년 전 조회 872
14년 전 조회 922
14년 전 조회 543
14년 전 조회 1,076
14년 전 조회 1,666
14년 전 조회 1,055
14년 전 조회 1,343
14년 전 조회 859
14년 전 조회 992
14년 전 조회 785
14년 전 조회 1,114
14년 전 조회 1,012
14년 전 조회 432
14년 전 조회 569
14년 전 조회 646
14년 전 조회 953
14년 전 조회 777
14년 전 조회 775
14년 전 조회 760
14년 전 조회 1,168
14년 전 조회 864
14년 전 조회 874
14년 전 조회 885
14년 전 조회 691
14년 전 조회 1,752
14년 전 조회 1,521
14년 전 조회 950
14년 전 조회 775
14년 전 조회 1,846
14년 전 조회 1,211
14년 전 조회 1,046
14년 전 조회 814
14년 전 조회 1,515
14년 전 조회 3,778
14년 전 조회 2,432
🐛 버그신고