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년 전 조회 806
14년 전 조회 781
14년 전 조회 1,566
14년 전 조회 1,377
14년 전 조회 2,438
14년 전 조회 1,370
14년 전 조회 969
14년 전 조회 3,496
14년 전 조회 1,712
14년 전 조회 1,133
14년 전 조회 1,502
14년 전 조회 846
14년 전 조회 1,980
14년 전 조회 921
14년 전 조회 1,346
14년 전 조회 851
14년 전 조회 1,370
14년 전 조회 1,619
14년 전 조회 1,130
14년 전 조회 909
14년 전 조회 1,139
14년 전 조회 1,037
14년 전 조회 2,074
14년 전 조회 1,252
14년 전 조회 939
14년 전 조회 855
14년 전 조회 1,458
14년 전 조회 2,745
14년 전 조회 843
14년 전 조회 2,665
14년 전 조회 1,785
14년 전 조회 1,016
14년 전 조회 1,240
14년 전 조회 1,127
14년 전 조회 1,117
14년 전 조회 642
14년 전 조회 842
14년 전 조회 947
14년 전 조회 1,322
14년 전 조회 1,013
14년 전 조회 1,374
14년 전 조회 1,136
14년 전 조회 1,254
14년 전 조회 852
14년 전 조회 1,157
14년 전 조회 1,072
14년 전 조회 933
14년 전 조회 835
14년 전 조회 1,306
14년 전 조회 1,711
14년 전 조회 1,085
14년 전 조회 918
14년 전 조회 3,453
14년 전 조회 980
14년 전 조회 859
14년 전 조회 2,239
14년 전 조회 1,647
14년 전 조회 2,169
14년 전 조회 721
14년 전 조회 978
14년 전 조회 820
14년 전 조회 658
14년 전 조회 763
14년 전 조회 878
14년 전 조회 1,626
14년 전 조회 981
14년 전 조회 1,048
14년 전 조회 653
14년 전 조회 1,199
14년 전 조회 1,785
14년 전 조회 1,174
14년 전 조회 1,451
14년 전 조회 966
14년 전 조회 1,114
14년 전 조회 903
14년 전 조회 1,233
14년 전 조회 1,124
14년 전 조회 551
14년 전 조회 694
14년 전 조회 747
14년 전 조회 1,073
14년 전 조회 898
14년 전 조회 905
14년 전 조회 874
14년 전 조회 1,288
14년 전 조회 987
14년 전 조회 993
14년 전 조회 1,000
14년 전 조회 814
14년 전 조회 1,869
14년 전 조회 1,642
14년 전 조회 1,067
14년 전 조회 901
14년 전 조회 1,971
14년 전 조회 1,334
14년 전 조회 1,172
14년 전 조회 928
14년 전 조회 1,635
14년 전 조회 3,894
14년 전 조회 2,548