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년 전 조회 665
14년 전 조회 648
14년 전 조회 1,438
14년 전 조회 1,246
14년 전 조회 2,343
14년 전 조회 1,248
14년 전 조회 846
14년 전 조회 3,361
14년 전 조회 1,587
14년 전 조회 1,003
14년 전 조회 1,363
14년 전 조회 725
14년 전 조회 1,843
14년 전 조회 771
14년 전 조회 1,209
14년 전 조회 717
14년 전 조회 1,247
14년 전 조회 1,484
14년 전 조회 990
14년 전 조회 778
14년 전 조회 998
14년 전 조회 932
14년 전 조회 1,950
14년 전 조회 1,118
14년 전 조회 821
14년 전 조회 717
14년 전 조회 1,328
14년 전 조회 2,617
14년 전 조회 711
14년 전 조회 2,541
14년 전 조회 1,655
14년 전 조회 886
14년 전 조회 1,100
14년 전 조회 998
14년 전 조회 994
14년 전 조회 507
14년 전 조회 714
14년 전 조회 819
14년 전 조회 1,180
14년 전 조회 874
14년 전 조회 1,234
14년 전 조회 1,018
14년 전 조회 1,119
14년 전 조회 721
14년 전 조회 1,030
14년 전 조회 927
14년 전 조회 803
14년 전 조회 695
14년 전 조회 1,178
14년 전 조회 1,588
14년 전 조회 941
14년 전 조회 781
14년 전 조회 3,314
14년 전 조회 841
14년 전 조회 724
14년 전 조회 2,114
14년 전 조회 1,512
14년 전 조회 2,031
14년 전 조회 597
14년 전 조회 851
14년 전 조회 706
14년 전 조회 547
14년 전 조회 630
14년 전 조회 755
14년 전 조회 1,501
14년 전 조회 861
14년 전 조회 908
14년 전 조회 533
14년 전 조회 1,064
14년 전 조회 1,653
14년 전 조회 1,043
14년 전 조회 1,331
14년 전 조회 847
14년 전 조회 978
14년 전 조회 772
14년 전 조회 1,099
14년 전 조회 1,002
14년 전 조회 419
14년 전 조회 553
14년 전 조회 631
14년 전 조회 939
14년 전 조회 765
14년 전 조회 762
14년 전 조회 750
14년 전 조회 1,152
14년 전 조회 855
14년 전 조회 860
14년 전 조회 873
14년 전 조회 678
14년 전 조회 1,741
14년 전 조회 1,510
14년 전 조회 937
14년 전 조회 765
14년 전 조회 1,833
14년 전 조회 1,199
14년 전 조회 1,037
14년 전 조회 797
14년 전 조회 1,503
14년 전 조회 3,765
14년 전 조회 2,422
🐛 버그신고