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년 전 조회 811
14년 전 조회 787
14년 전 조회 1,580
14년 전 조회 1,384
14년 전 조회 2,446
14년 전 조회 1,376
14년 전 조회 980
14년 전 조회 3,509
14년 전 조회 1,724
14년 전 조회 1,135
14년 전 조회 1,511
14년 전 조회 854
14년 전 조회 1,998
14년 전 조회 932
14년 전 조회 1,354
14년 전 조회 864
14년 전 조회 1,376
14년 전 조회 1,632
14년 전 조회 1,140
14년 전 조회 920
14년 전 조회 1,147
14년 전 조회 1,043
14년 전 조회 2,081
14년 전 조회 1,259
14년 전 조회 944
14년 전 조회 861
14년 전 조회 1,465
14년 전 조회 2,751
14년 전 조회 856
14년 전 조회 2,673
14년 전 조회 1,806
14년 전 조회 1,023
14년 전 조회 1,247
14년 전 조회 1,135
14년 전 조회 1,125
14년 전 조회 658
14년 전 조회 849
14년 전 조회 958
14년 전 조회 1,322
14년 전 조회 1,018
14년 전 조회 1,382
14년 전 조회 1,143
14년 전 조회 1,266
14년 전 조회 872
14년 전 조회 1,164
14년 전 조회 1,079
14년 전 조회 949
14년 전 조회 848
14년 전 조회 1,311
14년 전 조회 1,719
14년 전 조회 1,101
14년 전 조회 923
14년 전 조회 3,464
14년 전 조회 990
14년 전 조회 865
14년 전 조회 2,243
14년 전 조회 1,651
14년 전 조회 2,175
14년 전 조회 728
14년 전 조회 988
14년 전 조회 827
14년 전 조회 667
14년 전 조회 769
14년 전 조회 886
14년 전 조회 1,630
14년 전 조회 992
14년 전 조회 1,056
14년 전 조회 664
14년 전 조회 1,207
14년 전 조회 1,796
14년 전 조회 1,184
14년 전 조회 1,465
14년 전 조회 972
14년 전 조회 1,120
14년 전 조회 914
14년 전 조회 1,244
14년 전 조회 1,133
14년 전 조회 555
14년 전 조회 706
14년 전 조회 756
14년 전 조회 1,079
14년 전 조회 906
14년 전 조회 911
14년 전 조회 884
14년 전 조회 1,297
14년 전 조회 996
14년 전 조회 999
14년 전 조회 1,022
14년 전 조회 829
14년 전 조회 1,875
14년 전 조회 1,654
14년 전 조회 1,075
14년 전 조회 912
14년 전 조회 1,977
14년 전 조회 1,342
14년 전 조회 1,179
14년 전 조회 937
14년 전 조회 1,642
14년 전 조회 3,903
14년 전 조회 2,556