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년 전 조회 701
14년 전 조회 686
14년 전 조회 1,467
14년 전 조회 1,285
14년 전 조회 2,361
14년 전 조회 1,283
14년 전 조회 874
14년 전 조회 3,403
14년 전 조회 1,623
14년 전 조회 1,038
14년 전 조회 1,396
14년 전 조회 761
14년 전 조회 1,884
14년 전 조회 805
14년 전 조회 1,238
14년 전 조회 752
14년 전 조회 1,286
14년 전 조회 1,522
14년 전 조회 1,032
14년 전 조회 814
14년 전 조회 1,032
14년 전 조회 970
14년 전 조회 1,986
14년 전 조회 1,151
14년 전 조회 852
14년 전 조회 755
14년 전 조회 1,358
14년 전 조회 2,654
14년 전 조회 745
14년 전 조회 2,572
14년 전 조회 1,691
14년 전 조회 923
14년 전 조회 1,145
14년 전 조회 1,035
14년 전 조회 1,018
14년 전 조회 550
14년 전 조회 755
14년 전 조회 853
14년 전 조회 1,218
14년 전 조회 919
14년 전 조회 1,275
14년 전 조회 1,054
14년 전 조회 1,154
14년 전 조회 755
14년 전 조회 1,066
14년 전 조회 970
14년 전 조회 840
14년 전 조회 730
14년 전 조회 1,216
14년 전 조회 1,625
14년 전 조회 977
14년 전 조회 824
14년 전 조회 3,348
14년 전 조회 875
14년 전 조회 757
14년 전 조회 2,147
14년 전 조회 1,553
14년 전 조회 2,073
14년 전 조회 629
14년 전 조회 889
14년 전 조회 739
14년 전 조회 580
14년 전 조회 662
14년 전 조회 788
14년 전 조회 1,535
14년 전 조회 895
14년 전 조회 951
14년 전 조회 568
14년 전 조회 1,098
14년 전 조회 1,686
14년 전 조회 1,074
14년 전 조회 1,361
14년 전 조회 882
14년 전 조회 1,020
14년 전 조회 810
14년 전 조회 1,134
14년 전 조회 1,031
14년 전 조회 457
14년 전 조회 592
14년 전 조회 662
14년 전 조회 976
14년 전 조회 796
14년 전 조회 799
14년 전 조회 784
14년 전 조회 1,186
14년 전 조회 890
14년 전 조회 892
14년 전 조회 903
14년 전 조회 713
14년 전 조회 1,772
14년 전 조회 1,541
14년 전 조회 968
14년 전 조회 794
14년 전 조회 1,867
14년 전 조회 1,233
14년 전 조회 1,067
14년 전 조회 830
14년 전 조회 1,532
14년 전 조회 3,794
14년 전 조회 2,455