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,399
14년 전 조회 1,387
14년 전 조회 2,159
14년 전 조회 1,972
14년 전 조회 2,975
14년 전 조회 1,954
14년 전 조회 1,560
14년 전 조회 4,098
14년 전 조회 2,297
14년 전 조회 1,717
14년 전 조회 2,075
14년 전 조회 1,421
14년 전 조회 2,597
14년 전 조회 1,469
14년 전 조회 1,925
14년 전 조회 1,433
14년 전 조회 1,935
14년 전 조회 2,184
14년 전 조회 1,701
14년 전 조회 1,476
14년 전 조회 1,713
14년 전 조회 1,602
14년 전 조회 2,649
14년 전 조회 1,815
14년 전 조회 1,521
14년 전 조회 1,433
14년 전 조회 2,047
14년 전 조회 3,309
14년 전 조회 1,432
14년 전 조회 3,254
14년 전 조회 2,389
14년 전 조회 1,588
14년 전 조회 1,801
14년 전 조회 1,707
14년 전 조회 1,694
14년 전 조회 1,210
14년 전 조회 1,400
14년 전 조회 1,516
14년 전 조회 1,879
14년 전 조회 1,567
14년 전 조회 1,935
14년 전 조회 1,714
14년 전 조회 1,873
14년 전 조회 1,459
14년 전 조회 1,737
14년 전 조회 1,658
14년 전 조회 1,529
14년 전 조회 1,411
14년 전 조회 1,852
14년 전 조회 2,270
14년 전 조회 1,663
14년 전 조회 1,474
14년 전 조회 4,020
14년 전 조회 1,542
14년 전 조회 1,428
14년 전 조회 2,793
14년 전 조회 2,211
14년 전 조회 2,727
14년 전 조회 1,292
14년 전 조회 1,531
14년 전 조회 1,346
14년 전 조회 1,210
14년 전 조회 1,306
14년 전 조회 1,409
14년 전 조회 2,181
14년 전 조회 1,511
14년 전 조회 1,586
14년 전 조회 1,220
14년 전 조회 1,715
14년 전 조회 2,327
14년 전 조회 1,715
14년 전 조회 2,005
14년 전 조회 1,495
14년 전 조회 1,647
14년 전 조회 1,436
14년 전 조회 1,766
14년 전 조회 1,648
14년 전 조회 1,081
14년 전 조회 1,252
14년 전 조회 1,260
14년 전 조회 1,600
14년 전 조회 1,425
14년 전 조회 1,463
14년 전 조회 1,393
14년 전 조회 1,807
14년 전 조회 1,522
14년 전 조회 1,509
14년 전 조회 1,536
14년 전 조회 1,322
14년 전 조회 2,382
14년 전 조회 2,163
14년 전 조회 1,590
14년 전 조회 1,427
14년 전 조회 2,487
14년 전 조회 1,848
14년 전 조회 1,681
14년 전 조회 1,422
14년 전 조회 2,134
14년 전 조회 4,416
14년 전 조회 3,052