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,241
14년 전 조회 1,231
14년 전 조회 2,004
14년 전 조회 1,791
14년 전 조회 2,815
14년 전 조회 1,795
14년 전 조회 1,388
14년 전 조회 3,926
14년 전 조회 2,116
14년 전 조회 1,547
14년 전 조회 1,922
14년 전 조회 1,268
14년 전 조회 2,424
14년 전 조회 1,316
14년 전 조회 1,762
14년 전 조회 1,256
14년 전 조회 1,759
14년 전 조회 2,022
14년 전 조회 1,530
14년 전 조회 1,322
14년 전 조회 1,553
14년 전 조회 1,433
14년 전 조회 2,465
14년 전 조회 1,644
14년 전 조회 1,355
14년 전 조회 1,278
14년 전 조회 1,858
14년 전 조회 3,134
14년 전 조회 1,274
14년 전 조회 3,070
14년 전 조회 2,231
14년 전 조회 1,416
14년 전 조회 1,632
14년 전 조회 1,530
14년 전 조회 1,522
14년 전 조회 1,076
14년 전 조회 1,238
14년 전 조회 1,344
14년 전 조회 1,705
14년 전 조회 1,418
14년 전 조회 1,777
14년 전 조회 1,536
14년 전 조회 1,709
14년 전 조회 1,292
14년 전 조회 1,565
14년 전 조회 1,486
14년 전 조회 1,366
14년 전 조회 1,245
14년 전 조회 1,693
14년 전 조회 2,093
14년 전 조회 1,498
14년 전 조회 1,320
14년 전 조회 3,843
14년 전 조회 1,379
14년 전 조회 1,266
14년 전 조회 2,605
14년 전 조회 2,047
14년 전 조회 2,540
14년 전 조회 1,120
14년 전 조회 1,365
14년 전 조회 1,186
14년 전 조회 1,043
14년 전 조회 1,153
14년 전 조회 1,251
14년 전 조회 2,025
14년 전 조회 1,359
14년 전 조회 1,439
14년 전 조회 1,066
14년 전 조회 1,571
14년 전 조회 2,166
14년 전 조회 1,581
14년 전 조회 1,855
14년 전 조회 1,332
14년 전 조회 1,491
14년 전 조회 1,297
14년 전 조회 1,607
14년 전 조회 1,480
14년 전 조회 930
14년 전 조회 1,109
14년 전 조회 1,095
14년 전 조회 1,435
14년 전 조회 1,279
14년 전 조회 1,331
14년 전 조회 1,246
14년 전 조회 1,661
14년 전 조회 1,357
14년 전 조회 1,380
14년 전 조회 1,409
14년 전 조회 1,199
14년 전 조회 2,252
14년 전 조회 2,014
14년 전 조회 1,460
14년 전 조회 1,292
14년 전 조회 2,359
14년 전 조회 1,717
14년 전 조회 1,552
14년 전 조회 1,282
14년 전 조회 2,010
14년 전 조회 4,261
14년 전 조회 2,907