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년 전 조회 676
14년 전 조회 658
14년 전 조회 1,447
14년 전 조회 1,257
14년 전 조회 2,344
14년 전 조회 1,254
14년 전 조회 856
14년 전 조회 3,368
14년 전 조회 1,594
14년 전 조회 1,011
14년 전 조회 1,371
14년 전 조회 729
14년 전 조회 1,850
14년 전 조회 782
14년 전 조회 1,216
14년 전 조회 723
14년 전 조회 1,256
14년 전 조회 1,492
14년 전 조회 1,000
14년 전 조회 786
14년 전 조회 1,008
14년 전 조회 938
14년 전 조회 1,959
14년 전 조회 1,126
14년 전 조회 828
14년 전 조회 725
14년 전 조회 1,339
14년 전 조회 2,628
14년 전 조회 719
14년 전 조회 2,547
14년 전 조회 1,664
14년 전 조회 895
14년 전 조회 1,110
14년 전 조회 1,006
14년 전 조회 998
14년 전 조회 516
14년 전 조회 726
14년 전 조회 827
14년 전 조회 1,188
14년 전 조회 884
14년 전 조회 1,244
14년 전 조회 1,028
14년 전 조회 1,126
14년 전 조회 731
14년 전 조회 1,036
14년 전 조회 937
14년 전 조회 811
14년 전 조회 701
14년 전 조회 1,187
14년 전 조회 1,598
14년 전 조회 950
14년 전 조회 793
14년 전 조회 3,325
14년 전 조회 845
14년 전 조회 732
14년 전 조회 2,123
14년 전 조회 1,524
14년 전 조회 2,040
14년 전 조회 608
14년 전 조회 859
14년 전 조회 713
14년 전 조회 553
14년 전 조회 636
14년 전 조회 763
14년 전 조회 1,511
14년 전 조회 868
14년 전 조회 920
14년 전 조회 540
14년 전 조회 1,073
14년 전 조회 1,661
14년 전 조회 1,052
14년 전 조회 1,341
14년 전 조회 858
14년 전 조회 986
14년 전 조회 783
14년 전 조회 1,109
14년 전 조회 1,008
14년 전 조회 427
14년 전 조회 563
14년 전 조회 641
14년 전 조회 950
14년 전 조회 774
14년 전 조회 771
14년 전 조회 756
14년 전 조회 1,163
14년 전 조회 862
14년 전 조회 869
14년 전 조회 882
14년 전 조회 688
14년 전 조회 1,748
14년 전 조회 1,518
14년 전 조회 945
14년 전 조회 774
14년 전 조회 1,842
14년 전 조회 1,206
14년 전 조회 1,041
14년 전 조회 809
14년 전 조회 1,514
14년 전 조회 3,771
14년 전 조회 2,432
🐛 버그신고