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년 전 조회 778
14년 전 조회 743
14년 전 조회 1,525
14년 전 조회 1,332
14년 전 조회 2,416
14년 전 조회 1,337
14년 전 조회 935
14년 전 조회 3,454
14년 전 조회 1,677
14년 전 조회 1,099
14년 전 조회 1,463
14년 전 조회 812
14년 전 조회 1,940
14년 전 조회 883
14년 전 조회 1,309
14년 전 조회 818
14년 전 조회 1,339
14년 전 조회 1,581
14년 전 조회 1,100
14년 전 조회 886
14년 전 조회 1,104
14년 전 조회 999
14년 전 조회 2,046
14년 전 조회 1,212
14년 전 조회 906
14년 전 조회 813
14년 전 조회 1,419
14년 전 조회 2,702
14년 전 조회 810
14년 전 조회 2,638
14년 전 조회 1,758
14년 전 조회 976
14년 전 조회 1,204
14년 전 조회 1,092
14년 전 조회 1,083
14년 전 조회 608
14년 전 조회 807
14년 전 조회 910
14년 전 조회 1,292
14년 전 조회 976
14년 전 조회 1,340
14년 전 조회 1,103
14년 전 조회 1,211
14년 전 조회 822
14년 전 조회 1,116
14년 전 조회 1,036
14년 전 조회 890
14년 전 조회 790
14년 전 조회 1,264
14년 전 조회 1,674
14년 전 조회 1,042
14년 전 조회 885
14년 전 조회 3,410
14년 전 조회 936
14년 전 조회 816
14년 전 조회 2,197
14년 전 조회 1,606
14년 전 조회 2,131
14년 전 조회 685
14년 전 조회 942
14년 전 조회 790
14년 전 조회 618
14년 전 조회 722
14년 전 조회 848
14년 전 조회 1,593
14년 전 조회 945
14년 전 조회 1,005
14년 전 조회 624
14년 전 조회 1,158
14년 전 조회 1,740
14년 전 조회 1,135
14년 전 조회 1,415
14년 전 조회 921
14년 전 조회 1,079
14년 전 조회 875
14년 전 조회 1,194
14년 전 조회 1,084
14년 전 조회 509
14년 전 조회 651
14년 전 조회 701
14년 전 조회 1,040
14년 전 조회 867
14년 전 조회 868
14년 전 조회 829
14년 전 조회 1,254
14년 전 조회 952
14년 전 조회 960
14년 전 조회 963
14년 전 조회 774
14년 전 조회 1,827
14년 전 조회 1,605
14년 전 조회 1,026
14년 전 조회 854
14년 전 조회 1,930
14년 전 조회 1,301
14년 전 조회 1,140
14년 전 조회 890
14년 전 조회 1,604
14년 전 조회 3,861
14년 전 조회 2,507