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,143
14년 전 조회 1,117
14년 전 조회 1,898
14년 전 조회 1,683
14년 전 조회 2,734
14년 전 조회 1,691
14년 전 조회 1,308
14년 전 조회 3,825
14년 전 조회 2,028
14년 전 조회 1,448
14년 전 조회 1,811
14년 전 조회 1,174
14년 전 조회 2,350
14년 전 조회 1,238
14년 전 조회 1,663
14년 전 조회 1,173
14년 전 조회 1,675
14년 전 조회 1,933
14년 전 조회 1,434
14년 전 조회 1,217
14년 전 조회 1,449
14년 전 조회 1,341
14년 전 조회 2,377
14년 전 조회 1,561
14년 전 조회 1,247
14년 전 조회 1,180
14년 전 조회 1,760
14년 전 조회 3,035
14년 전 조회 1,175
14년 전 조회 2,978
14년 전 조회 2,161
14년 전 조회 1,325
14년 전 조회 1,538
14년 전 조회 1,436
14년 전 조회 1,427
14년 전 조회 975
14년 전 조회 1,156
14년 전 조회 1,253
14년 전 조회 1,625
14년 전 조회 1,314
14년 전 조회 1,683
14년 전 조회 1,446
14년 전 조회 1,648
14년 전 조회 1,213
14년 전 조회 1,482
14년 전 조회 1,402
14년 전 조회 1,263
14년 전 조회 1,151
14년 전 조회 1,603
14년 전 조회 2,002
14년 전 조회 1,396
14년 전 조회 1,233
14년 전 조회 3,738
14년 전 조회 1,290
14년 전 조회 1,172
14년 전 조회 2,513
14년 전 조회 1,955
14년 전 조회 2,456
14년 전 조회 1,020
14년 전 조회 1,258
14년 전 조회 1,093
14년 전 조회 955
14년 전 조회 1,055
14년 전 조회 1,162
14년 전 조회 1,927
14년 전 조회 1,265
14년 전 조회 1,344
14년 전 조회 965
14년 전 조회 1,474
14년 전 조회 2,063
14년 전 조회 1,489
14년 전 조회 1,746
14년 전 조회 1,245
14년 전 조회 1,395
14년 전 조회 1,206
14년 전 조회 1,527
14년 전 조회 1,382
14년 전 조회 838
14년 전 조회 1,006
14년 전 조회 1,034
14년 전 조회 1,351
14년 전 조회 1,190
14년 전 조회 1,204
14년 전 조회 1,160
14년 전 조회 1,581
14년 전 조회 1,276
14년 전 조회 1,295
14년 전 조회 1,347
14년 전 조회 1,110
14년 전 조회 2,160
14년 전 조회 1,917
14년 전 조회 1,367
14년 전 조회 1,206
14년 전 조회 2,285
14년 전 조회 1,635
14년 전 조회 1,481
14년 전 조회 1,197
14년 전 조회 1,913
14년 전 조회 4,173
14년 전 조회 2,828