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,103
14년 전 조회 1,073
14년 전 조회 1,852
14년 전 조회 1,636
14년 전 조회 2,681
14년 전 조회 1,649
14년 전 조회 1,254
14년 전 조회 3,774
14년 전 조회 1,975
14년 전 조회 1,409
14년 전 조회 1,764
14년 전 조회 1,117
14년 전 조회 2,316
14년 전 조회 1,196
14년 전 조회 1,618
14년 전 조회 1,123
14년 전 조회 1,628
14년 전 조회 1,880
14년 전 조회 1,385
14년 전 조회 1,178
14년 전 조회 1,407
14년 전 조회 1,287
14년 전 조회 2,333
14년 전 조회 1,518
14년 전 조회 1,198
14년 전 조회 1,136
14년 전 조회 1,718
14년 전 조회 2,990
14년 전 조회 1,129
14년 전 조회 2,932
14년 전 조회 2,129
14년 전 조회 1,273
14년 전 조회 1,495
14년 전 조회 1,387
14년 전 조회 1,374
14년 전 조회 930
14년 전 조회 1,104
14년 전 조회 1,207
14년 전 조회 1,576
14년 전 조회 1,265
14년 전 조회 1,635
14년 전 조회 1,391
14년 전 조회 1,617
14년 전 조회 1,189
14년 전 조회 1,432
14년 전 조회 1,343
14년 전 조회 1,207
14년 전 조회 1,101
14년 전 조회 1,554
14년 전 조회 1,950
14년 전 조회 1,347
14년 전 조회 1,174
14년 전 조회 3,691
14년 전 조회 1,235
14년 전 조회 1,126
14년 전 조회 2,467
14년 전 조회 1,896
14년 전 조회 2,400
14년 전 조회 970
14년 전 조회 1,215
14년 전 조회 1,046
14년 전 조회 894
14년 전 조회 1,006
14년 전 조회 1,108
14년 전 조회 1,875
14년 전 조회 1,221
14년 전 조회 1,298
14년 전 조회 914
14년 전 조회 1,431
14년 전 조회 2,017
14년 전 조회 1,438
14년 전 조회 1,692
14년 전 조회 1,195
14년 전 조회 1,357
14년 전 조회 1,160
14년 전 조회 1,474
14년 전 조회 1,344
14년 전 조회 788
14년 전 조회 956
14년 전 조회 978
14년 전 조회 1,306
14년 전 조회 1,131
14년 전 조회 1,158
14년 전 조회 1,108
14년 전 조회 1,525
14년 전 조회 1,218
14년 전 조회 1,244
14년 전 조회 1,314
14년 전 조회 1,062
14년 전 조회 2,107
14년 전 조회 1,869
14년 전 조회 1,319
14년 전 조회 1,151
14년 전 조회 2,226
14년 전 조회 1,580
14년 전 조회 1,422
14년 전 조회 1,151
14년 전 조회 1,858
14년 전 조회 4,118
14년 전 조회 2,777