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년 전 조회 667
14년 전 조회 651
14년 전 조회 1,441
14년 전 조회 1,251
14년 전 조회 2,343
14년 전 조회 1,251
14년 전 조회 850
14년 전 조회 3,364
14년 전 조회 1,591
14년 전 조회 1,006
14년 전 조회 1,365
14년 전 조회 726
14년 전 조회 1,846
14년 전 조회 775
14년 전 조회 1,210
14년 전 조회 719
14년 전 조회 1,249
14년 전 조회 1,487
14년 전 조회 995
14년 전 조회 779
14년 전 조회 1,001
14년 전 조회 934
14년 전 조회 1,951
14년 전 조회 1,122
14년 전 조회 824
14년 전 조회 721
14년 전 조회 1,333
14년 전 조회 2,619
14년 전 조회 714
14년 전 조회 2,544
14년 전 조회 1,660
14년 전 조회 891
14년 전 조회 1,106
14년 전 조회 1,001
14년 전 조회 995
14년 전 조회 509
14년 전 조회 717
14년 전 조회 821
14년 전 조회 1,182
14년 전 조회 880
14년 전 조회 1,238
14년 전 조회 1,020
14년 전 조회 1,123
14년 전 조회 725
14년 전 조회 1,031
14년 전 조회 931
14년 전 조회 806
14년 전 조회 699
14년 전 조회 1,181
14년 전 조회 1,592
14년 전 조회 945
14년 전 조회 786
14년 전 조회 3,320
14년 전 조회 843
14년 전 조회 727
14년 전 조회 2,117
14년 전 조회 1,516
14년 전 조회 2,034
14년 전 조회 601
14년 전 조회 852
14년 전 조회 708
14년 전 조회 548
14년 전 조회 632
14년 전 조회 759
14년 전 조회 1,505
14년 전 조회 863
14년 전 조회 913
14년 전 조회 535
14년 전 조회 1,066
14년 전 조회 1,658
14년 전 조회 1,045
14년 전 조회 1,334
14년 전 조회 850
14년 전 조회 981
14년 전 조회 775
14년 전 조회 1,101
14년 전 조회 1,004
14년 전 조회 424
14년 전 조회 558
14년 전 조회 635
14년 전 조회 945
14년 전 조회 768
14년 전 조회 765
14년 전 조회 751
14년 전 조회 1,158
14년 전 조회 857
14년 전 조회 862
14년 전 조회 877
14년 전 조회 685
14년 전 조회 1,744
14년 전 조회 1,513
14년 전 조회 941
14년 전 조회 767
14년 전 조회 1,834
14년 전 조회 1,200
14년 전 조회 1,038
14년 전 조회 800
14년 전 조회 1,506
14년 전 조회 3,767
14년 전 조회 2,426
🐛 버그신고