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년 전 조회 1,436
14년 전 조회 1,426
14년 전 조회 2,203
14년 전 조회 2,001
14년 전 조회 3,003
14년 전 조회 1,984
14년 전 조회 1,599
14년 전 조회 4,134
14년 전 조회 2,322
14년 전 조회 1,753
14년 전 조회 2,105
14년 전 조회 1,457
14년 전 조회 2,632
14년 전 조회 1,508
14년 전 조회 1,955
14년 전 조회 1,468
14년 전 조회 1,979
14년 전 조회 2,220
14년 전 조회 1,735
14년 전 조회 1,515
14년 전 조회 1,765
14년 전 조회 1,639
14년 전 조회 2,685
14년 전 조회 1,845
14년 전 조회 1,553
14년 전 조회 1,470
14년 전 조회 2,076
14년 전 조회 3,346
14년 전 조회 1,463
14년 전 조회 3,299
14년 전 조회 2,424
14년 전 조회 1,617
14년 전 조회 1,828
14년 전 조회 1,739
14년 전 조회 1,726
14년 전 조회 1,243
14년 전 조회 1,440
14년 전 조회 1,555
14년 전 조회 1,914
14년 전 조회 1,602
14년 전 조회 1,969
14년 전 조회 1,748
14년 전 조회 1,901
14년 전 조회 1,499
14년 전 조회 1,772
14년 전 조회 1,688
14년 전 조회 1,567
14년 전 조회 1,452
14년 전 조회 1,891
14년 전 조회 2,298
14년 전 조회 1,695
14년 전 조회 1,512
14년 전 조회 4,049
14년 전 조회 1,576
14년 전 조회 1,462
14년 전 조회 2,814
14년 전 조회 2,241
14년 전 조회 2,761
14년 전 조회 1,326
14년 전 조회 1,559
14년 전 조회 1,378
14년 전 조회 1,239
14년 전 조회 1,336
14년 전 조회 1,457
14년 전 조회 2,213
14년 전 조회 1,550
14년 전 조회 1,626
14년 전 조회 1,252
14년 전 조회 1,751
14년 전 조회 2,370
14년 전 조회 1,757
14년 전 조회 2,039
14년 전 조회 1,540
14년 전 조회 1,679
14년 전 조회 1,480
14년 전 조회 1,808
14년 전 조회 1,691
14년 전 조회 1,118
14년 전 조회 1,290
14년 전 조회 1,296
14년 전 조회 1,635
14년 전 조회 1,472
14년 전 조회 1,502
14년 전 조회 1,430
14년 전 조회 1,843
14년 전 조회 1,564
14년 전 조회 1,558
14년 전 조회 1,570
14년 전 조회 1,372
14년 전 조회 2,416
14년 전 조회 2,199
14년 전 조회 1,622
14년 전 조회 1,452
14년 전 조회 2,526
14년 전 조회 1,884
14년 전 조회 1,719
14년 전 조회 1,447
14년 전 조회 2,160
14년 전 조회 4,439
14년 전 조회 3,076