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,116
14년 전 조회 1,085
14년 전 조회 1,861
14년 전 조회 1,653
14년 전 조회 2,695
14년 전 조회 1,659
14년 전 조회 1,264
14년 전 조회 3,786
14년 전 조회 1,986
14년 전 조회 1,415
14년 전 조회 1,775
14년 전 조회 1,130
14년 전 조회 2,327
14년 전 조회 1,204
14년 전 조회 1,631
14년 전 조회 1,138
14년 전 조회 1,641
14년 전 조회 1,890
14년 전 조회 1,400
14년 전 조회 1,192
14년 전 조회 1,420
14년 전 조회 1,303
14년 전 조회 2,343
14년 전 조회 1,532
14년 전 조회 1,211
14년 전 조회 1,147
14년 전 조회 1,727
14년 전 조회 3,001
14년 전 조회 1,143
14년 전 조회 2,942
14년 전 조회 2,139
14년 전 조회 1,290
14년 전 조회 1,505
14년 전 조회 1,399
14년 전 조회 1,389
14년 전 조회 943
14년 전 조회 1,117
14년 전 조회 1,217
14년 전 조회 1,588
14년 전 조회 1,280
14년 전 조회 1,646
14년 전 조회 1,407
14년 전 조회 1,627
14년 전 조회 1,195
14년 전 조회 1,441
14년 전 조회 1,355
14년 전 조회 1,220
14년 전 조회 1,112
14년 전 조회 1,567
14년 전 조회 1,964
14년 전 조회 1,363
14년 전 조회 1,183
14년 전 조회 3,704
14년 전 조회 1,250
14년 전 조회 1,138
14년 전 조회 2,481
14년 전 조회 1,910
14년 전 조회 2,414
14년 전 조회 981
14년 전 조회 1,225
14년 전 조회 1,057
14년 전 조회 912
14년 전 조회 1,017
14년 전 조회 1,125
14년 전 조회 1,889
14년 전 조회 1,236
14년 전 조회 1,305
14년 전 조회 928
14년 전 조회 1,445
14년 전 조회 2,023
14년 전 조회 1,447
14년 전 조회 1,702
14년 전 조회 1,211
14년 전 조회 1,370
14년 전 조회 1,174
14년 전 조회 1,489
14년 전 조회 1,353
14년 전 조회 800
14년 전 조회 971
14년 전 조회 1,000
14년 전 조회 1,319
14년 전 조회 1,145
14년 전 조회 1,169
14년 전 조회 1,124
14년 전 조회 1,547
14년 전 조회 1,227
14년 전 조회 1,253
14년 전 조회 1,326
14년 전 조회 1,074
14년 전 조회 2,120
14년 전 조회 1,882
14년 전 조회 1,329
14년 전 조회 1,166
14년 전 조회 2,246
14년 전 조회 1,599
14년 전 조회 1,445
14년 전 조회 1,157
14년 전 조회 1,874
14년 전 조회 4,135
14년 전 조회 2,791