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년 전 조회 664
14년 전 조회 643
14년 전 조회 1,434
14년 전 조회 1,245
14년 전 조회 2,341
14년 전 조회 1,245
14년 전 조회 841
14년 전 조회 3,358
14년 전 조회 1,583
14년 전 조회 999
14년 전 조회 1,359
14년 전 조회 719
14년 전 조회 1,839
14년 전 조회 770
14년 전 조회 1,205
14년 전 조회 713
14년 전 조회 1,245
14년 전 조회 1,479
14년 전 조회 990
14년 전 조회 776
14년 전 조회 994
14년 전 조회 927
14년 전 조회 1,946
14년 전 조회 1,115
14년 전 조회 818
14년 전 조회 715
14년 전 조회 1,325
14년 전 조회 2,613
14년 전 조회 708
14년 전 조회 2,537
14년 전 조회 1,652
14년 전 조회 885
14년 전 조회 1,100
14년 전 조회 995
14년 전 조회 988
14년 전 조회 504
14년 전 조회 711
14년 전 조회 814
14년 전 조회 1,179
14년 전 조회 873
14년 전 조회 1,232
14년 전 조회 1,015
14년 전 조회 1,116
14년 전 조회 717
14년 전 조회 1,027
14년 전 조회 922
14년 전 조회 798
14년 전 조회 692
14년 전 조회 1,176
14년 전 조회 1,586
14년 전 조회 940
14년 전 조회 778
14년 전 조회 3,311
14년 전 조회 837
14년 전 조회 720
14년 전 조회 2,111
14년 전 조회 1,507
14년 전 조회 2,026
14년 전 조회 596
14년 전 조회 847
14년 전 조회 702
14년 전 조회 542
14년 전 조회 626
14년 전 조회 753
14년 전 조회 1,499
14년 전 조회 858
14년 전 조회 907
14년 전 조회 530
14년 전 조회 1,061
14년 전 조회 1,651
14년 전 조회 1,041
14년 전 조회 1,330
14년 전 조회 846
14년 전 조회 976
14년 전 조회 768
14년 전 조회 1,096
14년 전 조회 999
14년 전 조회 418
14년 전 조회 552
14년 전 조회 629
14년 전 조회 939
14년 전 조회 763
14년 전 조회 760
14년 전 조회 744
14년 전 조회 1,151
14년 전 조회 851
14년 전 조회 858
14년 전 조회 871
14년 전 조회 678
14년 전 조회 1,738
14년 전 조회 1,507
14년 전 조회 935
14년 전 조회 760
14년 전 조회 1,831
14년 전 조회 1,197
14년 전 조회 1,036
14년 전 조회 796
14년 전 조회 1,502
14년 전 조회 3,761
14년 전 조회 2,420
🐛 버그신고