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년 전 조회 687
14년 전 조회 670
14년 전 조회 1,460
14년 전 조회 1,269
14년 전 조회 2,350
14년 전 조회 1,267
14년 전 조회 864
14년 전 조회 3,383
14년 전 조회 1,605
14년 전 조회 1,023
14년 전 조회 1,381
14년 전 조회 739
14년 전 조회 1,862
14년 전 조회 793
14년 전 조회 1,227
14년 전 조회 735
14년 전 조회 1,268
14년 전 조회 1,504
14년 전 조회 1,013
14년 전 조회 799
14년 전 조회 1,015
14년 전 조회 954
14년 전 조회 1,969
14년 전 조회 1,136
14년 전 조회 840
14년 전 조회 737
14년 전 조회 1,350
14년 전 조회 2,640
14년 전 조회 730
14년 전 조회 2,558
14년 전 조회 1,676
14년 전 조회 907
14년 전 조회 1,128
14년 전 조회 1,017
14년 전 조회 1,010
14년 전 조회 528
14년 전 조회 739
14년 전 조회 841
14년 전 조회 1,197
14년 전 조회 897
14년 전 조회 1,255
14년 전 조회 1,039
14년 전 조회 1,140
14년 전 조회 743
14년 전 조회 1,051
14년 전 조회 953
14년 전 조회 825
14년 전 조회 715
14년 전 조회 1,200
14년 전 조회 1,612
14년 전 조회 966
14년 전 조회 803
14년 전 조회 3,339
14년 전 조회 862
14년 전 조회 741
14년 전 조회 2,133
14년 전 조회 1,537
14년 전 조회 2,054
14년 전 조회 618
14년 전 조회 871
14년 전 조회 726
14년 전 조회 567
14년 전 조회 650
14년 전 조회 779
14년 전 조회 1,522
14년 전 조회 880
14년 전 조회 931
14년 전 조회 550
14년 전 조회 1,084
14년 전 조회 1,674
14년 전 조회 1,062
14년 전 조회 1,352
14년 전 조회 868
14년 전 조회 999
14년 전 조회 795
14년 전 조회 1,119
14년 전 조회 1,021
14년 전 조회 443
14년 전 조회 575
14년 전 조회 653
14년 전 조회 963
14년 전 조회 785
14년 전 조회 783
14년 전 조회 768
14년 전 조회 1,174
14년 전 조회 874
14년 전 조회 884
14년 전 조회 892
14년 전 조회 697
14년 전 조회 1,758
14년 전 조회 1,529
14년 전 조회 954
14년 전 조회 787
14년 전 조회 1,854
14년 전 조회 1,221
14년 전 조회 1,057
14년 전 조회 819
14년 전 조회 1,521
14년 전 조회 3,786
14년 전 조회 2,440
🐛 버그신고