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,398
14년 전 조회 1,385
14년 전 조회 2,155
14년 전 조회 1,967
14년 전 조회 2,972
14년 전 조회 1,949
14년 전 조회 1,553
14년 전 조회 4,090
14년 전 조회 2,292
14년 전 조회 1,712
14년 전 조회 2,073
14년 전 조회 1,418
14년 전 조회 2,593
14년 전 조회 1,466
14년 전 조회 1,920
14년 전 조회 1,431
14년 전 조회 1,931
14년 전 조회 2,178
14년 전 조회 1,698
14년 전 조회 1,474
14년 전 조회 1,712
14년 전 조회 1,598
14년 전 조회 2,644
14년 전 조회 1,807
14년 전 조회 1,519
14년 전 조회 1,430
14년 전 조회 2,042
14년 전 조회 3,304
14년 전 조회 1,429
14년 전 조회 3,246
14년 전 조회 2,385
14년 전 조회 1,581
14년 전 조회 1,797
14년 전 조회 1,705
14년 전 조회 1,690
14년 전 조회 1,207
14년 전 조회 1,397
14년 전 조회 1,514
14년 전 조회 1,876
14년 전 조회 1,562
14년 전 조회 1,930
14년 전 조회 1,707
14년 전 조회 1,866
14년 전 조회 1,456
14년 전 조회 1,734
14년 전 조회 1,651
14년 전 조회 1,527
14년 전 조회 1,409
14년 전 조회 1,849
14년 전 조회 2,262
14년 전 조회 1,662
14년 전 조회 1,468
14년 전 조회 4,017
14년 전 조회 1,538
14년 전 조회 1,422
14년 전 조회 2,788
14년 전 조회 2,208
14년 전 조회 2,723
14년 전 조회 1,288
14년 전 조회 1,527
14년 전 조회 1,339
14년 전 조회 1,208
14년 전 조회 1,303
14년 전 조회 1,407
14년 전 조회 2,179
14년 전 조회 1,508
14년 전 조회 1,581
14년 전 조회 1,216
14년 전 조회 1,711
14년 전 조회 2,321
14년 전 조회 1,710
14년 전 조회 2,000
14년 전 조회 1,492
14년 전 조회 1,647
14년 전 조회 1,432
14년 전 조회 1,765
14년 전 조회 1,644
14년 전 조회 1,077
14년 전 조회 1,248
14년 전 조회 1,258
14년 전 조회 1,595
14년 전 조회 1,425
14년 전 조회 1,461
14년 전 조회 1,392
14년 전 조회 1,805
14년 전 조회 1,518
14년 전 조회 1,508
14년 전 조회 1,533
14년 전 조회 1,321
14년 전 조회 2,381
14년 전 조회 2,161
14년 전 조회 1,588
14년 전 조회 1,426
14년 전 조회 2,482
14년 전 조회 1,844
14년 전 조회 1,679
14년 전 조회 1,417
14년 전 조회 2,132
14년 전 조회 4,416
14년 전 조회 3,050