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,373
14년 전 조회 1,367
14년 전 조회 2,147
14년 전 조회 1,937
14년 전 조회 2,949
14년 전 조회 1,930
14년 전 조회 1,535
14년 전 조회 4,068
14년 전 조회 2,279
14년 전 조회 1,691
14년 전 조회 2,055
14년 전 조회 1,394
14년 전 조회 2,567
14년 전 조회 1,449
14년 전 조회 1,905
14년 전 조회 1,407
14년 전 조회 1,909
14년 전 조회 2,158
14년 전 조회 1,679
14년 전 조회 1,451
14년 전 조회 1,686
14년 전 조회 1,578
14년 전 조회 2,616
14년 전 조회 1,783
14년 전 조회 1,502
14년 전 조회 1,413
14년 전 조회 2,012
14년 전 조회 3,289
14년 전 조회 1,407
14년 전 조회 3,217
14년 전 조회 2,363
14년 전 조회 1,559
14년 전 조회 1,772
14년 전 조회 1,691
14년 전 조회 1,670
14년 전 조회 1,187
14년 전 조회 1,374
14년 전 조회 1,492
14년 전 조회 1,855
14년 전 조회 1,542
14년 전 조회 1,902
14년 전 조회 1,687
14년 전 조회 1,837
14년 전 조회 1,439
14년 전 조회 1,711
14년 전 조회 1,637
14년 전 조회 1,506
14년 전 조회 1,385
14년 전 조회 1,827
14년 전 조회 2,240
14년 전 조회 1,633
14년 전 조회 1,449
14년 전 조회 3,989
14년 전 조회 1,512
14년 전 조회 1,401
14년 전 조회 2,763
14년 전 조회 2,190
14년 전 조회 2,696
14년 전 조회 1,268
14년 전 조회 1,509
14년 전 조회 1,317
14년 전 조회 1,195
14년 전 조회 1,272
14년 전 조회 1,386
14년 전 조회 2,159
14년 전 조회 1,491
14년 전 조회 1,565
14년 전 조회 1,195
14년 전 조회 1,686
14년 전 조회 2,306
14년 전 조회 1,692
14년 전 조회 1,985
14년 전 조회 1,484
14년 전 조회 1,634
14년 전 조회 1,412
14년 전 조회 1,739
14년 전 조회 1,621
14년 전 조회 1,059
14년 전 조회 1,227
14년 전 조회 1,237
14년 전 조회 1,573
14년 전 조회 1,407
14년 전 조회 1,446
14년 전 조회 1,375
14년 전 조회 1,788
14년 전 조회 1,494
14년 전 조회 1,497
14년 전 조회 1,518
14년 전 조회 1,302
14년 전 조회 2,369
14년 전 조회 2,142
14년 전 조회 1,572
14년 전 조회 1,412
14년 전 조회 2,466
14년 전 조회 1,833
14년 전 조회 1,665
14년 전 조회 1,405
14년 전 조회 2,116
14년 전 조회 4,402
14년 전 조회 3,037