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,336
14년 전 조회 1,326
14년 전 조회 2,127
14년 전 조회 1,907
14년 전 조회 2,923
14년 전 조회 1,888
14년 전 조회 1,514
14년 전 조회 4,041
14년 전 조회 2,252
14년 전 조회 1,663
14년 전 조회 2,030
14년 전 조회 1,367
14년 전 조회 2,544
14년 전 조회 1,416
14년 전 조회 1,879
14년 전 조회 1,377
14년 전 조회 1,872
14년 전 조회 2,127
14년 전 조회 1,650
14년 전 조회 1,425
14년 전 조회 1,658
14년 전 조회 1,550
14년 전 조회 2,585
14년 전 조회 1,751
14년 전 조회 1,464
14년 전 조회 1,383
14년 전 조회 1,983
14년 전 조회 3,251
14년 전 조회 1,386
14년 전 조회 3,188
14년 전 조회 2,345
14년 전 조회 1,537
14년 전 조회 1,737
14년 전 조회 1,671
14년 전 조회 1,645
14년 전 조회 1,163
14년 전 조회 1,346
14년 전 조회 1,468
14년 전 조회 1,822
14년 전 조회 1,510
14년 전 조회 1,885
14년 전 조회 1,660
14년 전 조회 1,805
14년 전 조회 1,415
14년 전 조회 1,679
14년 전 조회 1,607
14년 전 조회 1,474
14년 전 조회 1,347
14년 전 조회 1,783
14년 전 조회 2,208
14년 전 조회 1,604
14년 전 조회 1,418
14년 전 조회 3,959
14년 전 조회 1,494
14년 전 조회 1,378
14년 전 조회 2,725
14년 전 조회 2,161
14년 전 조회 2,662
14년 전 조회 1,239
14년 전 조회 1,474
14년 전 조회 1,289
14년 전 조회 1,173
14년 전 조회 1,247
14년 전 조회 1,359
14년 전 조회 2,138
14년 전 조회 1,471
14년 전 조회 1,544
14년 전 조회 1,163
14년 전 조회 1,662
14년 전 조회 2,277
14년 전 조회 1,666
14년 전 조회 1,961
14년 전 조회 1,467
14년 전 조회 1,604
14년 전 조회 1,391
14년 전 조회 1,716
14년 전 조회 1,591
14년 전 조회 1,040
14년 전 조회 1,210
14년 전 조회 1,205
14년 전 조회 1,551
14년 전 조회 1,383
14년 전 조회 1,423
14년 전 조회 1,350
14년 전 조회 1,761
14년 전 조회 1,462
14년 전 조회 1,476
14년 전 조회 1,490
14년 전 조회 1,279
14년 전 조회 2,347
14년 전 조회 2,118
14년 전 조회 1,552
14년 전 조회 1,380
14년 전 조회 2,447
14년 전 조회 1,807
14년 전 조회 1,646
14년 전 조회 1,378
14년 전 조회 2,096
14년 전 조회 4,370
14년 전 조회 3,010