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,106
14년 전 조회 1,075
14년 전 조회 1,856
14년 전 조회 1,639
14년 전 조회 2,682
14년 전 조회 1,650
14년 전 조회 1,256
14년 전 조회 3,777
14년 전 조회 1,977
14년 전 조회 1,411
14년 전 조회 1,766
14년 전 조회 1,119
14년 전 조회 2,322
14년 전 조회 1,200
14년 전 조회 1,623
14년 전 조회 1,127
14년 전 조회 1,632
14년 전 조회 1,882
14년 전 조회 1,388
14년 전 조회 1,178
14년 전 조회 1,411
14년 전 조회 1,289
14년 전 조회 2,335
14년 전 조회 1,520
14년 전 조회 1,200
14년 전 조회 1,138
14년 전 조회 1,720
14년 전 조회 2,993
14년 전 조회 1,133
14년 전 조회 2,935
14년 전 조회 2,133
14년 전 조회 1,277
14년 전 조회 1,499
14년 전 조회 1,390
14년 전 조회 1,377
14년 전 조회 933
14년 전 조회 1,104
14년 전 조회 1,207
14년 전 조회 1,579
14년 전 조회 1,270
14년 전 조회 1,637
14년 전 조회 1,395
14년 전 조회 1,619
14년 전 조회 1,191
14년 전 조회 1,435
14년 전 조회 1,348
14년 전 조회 1,210
14년 전 조회 1,103
14년 전 조회 1,559
14년 전 조회 1,956
14년 전 조회 1,350
14년 전 조회 1,177
14년 전 조회 3,692
14년 전 조회 1,238
14년 전 조회 1,130
14년 전 조회 2,469
14년 전 조회 1,900
14년 전 조회 2,403
14년 전 조회 970
14년 전 조회 1,216
14년 전 조회 1,046
14년 전 조회 896
14년 전 조회 1,006
14년 전 조회 1,108
14년 전 조회 1,877
14년 전 조회 1,223
14년 전 조회 1,298
14년 전 조회 917
14년 전 조회 1,434
14년 전 조회 2,018
14년 전 조회 1,440
14년 전 조회 1,695
14년 전 조회 1,200
14년 전 조회 1,358
14년 전 조회 1,162
14년 전 조회 1,478
14년 전 조회 1,347
14년 전 조회 791
14년 전 조회 959
14년 전 조회 982
14년 전 조회 1,308
14년 전 조회 1,133
14년 전 조회 1,163
14년 전 조회 1,110
14년 전 조회 1,532
14년 전 조회 1,220
14년 전 조회 1,245
14년 전 조회 1,319
14년 전 조회 1,065
14년 전 조회 2,110
14년 전 조회 1,873
14년 전 조회 1,322
14년 전 조회 1,154
14년 전 조회 2,234
14년 전 조회 1,586
14년 전 조회 1,428
14년 전 조회 1,154
14년 전 조회 1,859
14년 전 조회 4,122
14년 전 조회 2,779