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년 전 조회 683
14년 전 조회 662
14년 전 조회 1,452
14년 전 조회 1,264
14년 전 조회 2,347
14년 전 조회 1,260
14년 전 조회 858
14년 전 조회 3,376
14년 전 조회 1,600
14년 전 조회 1,017
14년 전 조회 1,376
14년 전 조회 735
14년 전 조회 1,857
14년 전 조회 787
14년 전 조회 1,222
14년 전 조회 731
14년 전 조회 1,261
14년 전 조회 1,500
14년 전 조회 1,008
14년 전 조회 791
14년 전 조회 1,012
14년 전 조회 947
14년 전 조회 1,966
14년 전 조회 1,133
14년 전 조회 836
14년 전 조회 733
14년 전 조회 1,346
14년 전 조회 2,636
14년 전 조회 725
14년 전 조회 2,554
14년 전 조회 1,672
14년 전 조회 903
14년 전 조회 1,120
14년 전 조회 1,014
14년 전 조회 1,005
14년 전 조회 522
14년 전 조회 732
14년 전 조회 835
14년 전 조회 1,194
14년 전 조회 891
14년 전 조회 1,249
14년 전 조회 1,034
14년 전 조회 1,135
14년 전 조회 736
14년 전 조회 1,045
14년 전 조회 944
14년 전 조회 820
14년 전 조회 709
14년 전 조회 1,194
14년 전 조회 1,604
14년 전 조회 959
14년 전 조회 800
14년 전 조회 3,333
14년 전 조회 855
14년 전 조회 738
14년 전 조회 2,130
14년 전 조회 1,530
14년 전 조회 2,047
14년 전 조회 616
14년 전 조회 868
14년 전 조회 721
14년 전 조회 559
14년 전 조회 645
14년 전 조회 771
14년 전 조회 1,519
14년 전 조회 876
14년 전 조회 925
14년 전 조회 544
14년 전 조회 1,079
14년 전 조회 1,669
14년 전 조회 1,058
14년 전 조회 1,343
14년 전 조회 863
14년 전 조회 995
14년 전 조회 789
14년 전 조회 1,117
14년 전 조회 1,014
14년 전 조회 436
14년 전 조회 572
14년 전 조회 649
14년 전 조회 957
14년 전 조회 781
14년 전 조회 778
14년 전 조회 764
14년 전 조회 1,170
14년 전 조회 868
14년 전 조회 878
14년 전 조회 888
14년 전 조회 696
14년 전 조회 1,753
14년 전 조회 1,526
14년 전 조회 952
14년 전 조회 780
14년 전 조회 1,849
14년 전 조회 1,213
14년 전 조회 1,052
14년 전 조회 816
14년 전 조회 1,516
14년 전 조회 3,780
14년 전 조회 2,437
🐛 버그신고