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,454
14년 전 조회 1,449
14년 전 조회 2,229
14년 전 조회 2,017
14년 전 조회 3,022
14년 전 조회 2,009
14년 전 조회 1,621
14년 전 조회 4,156
14년 전 조회 2,335
14년 전 조회 1,774
14년 전 조회 2,125
14년 전 조회 1,479
14년 전 조회 2,647
14년 전 조회 1,530
14년 전 조회 1,971
14년 전 조회 1,488
14년 전 조회 1,999
14년 전 조회 2,242
14년 전 조회 1,757
14년 전 조회 1,538
14년 전 조회 1,785
14년 전 조회 1,657
14년 전 조회 2,705
14년 전 조회 1,865
14년 전 조회 1,576
14년 전 조회 1,485
14년 전 조회 2,101
14년 전 조회 3,366
14년 전 조회 1,486
14년 전 조회 3,323
14년 전 조회 2,446
14년 전 조회 1,640
14년 전 조회 1,846
14년 전 조회 1,762
14년 전 조회 1,744
14년 전 조회 1,269
14년 전 조회 1,463
14년 전 조회 1,572
14년 전 조회 1,930
14년 전 조회 1,624
14년 전 조회 1,984
14년 전 조회 1,768
14년 전 조회 1,922
14년 전 조회 1,522
14년 전 조회 1,792
14년 전 조회 1,710
14년 전 조회 1,586
14년 전 조회 1,471
14년 전 조회 1,912
14년 전 조회 2,319
14년 전 조회 1,716
14년 전 조회 1,532
14년 전 조회 4,066
14년 전 조회 1,604
14년 전 조회 1,487
14년 전 조회 2,840
14년 전 조회 2,266
14년 전 조회 2,786
14년 전 조회 1,345
14년 전 조회 1,585
14년 전 조회 1,399
14년 전 조회 1,261
14년 전 조회 1,360
14년 전 조회 1,475
14년 전 조회 2,230
14년 전 조회 1,576
14년 전 조회 1,652
14년 전 조회 1,276
14년 전 조회 1,771
14년 전 조회 2,390
14년 전 조회 1,789
14년 전 조회 2,062
14년 전 조회 1,563
14년 전 조회 1,707
14년 전 조회 1,511
14년 전 조회 1,836
14년 전 조회 1,715
14년 전 조회 1,141
14년 전 조회 1,321
14년 전 조회 1,315
14년 전 조회 1,656
14년 전 조회 1,497
14년 전 조회 1,524
14년 전 조회 1,451
14년 전 조회 1,860
14년 전 조회 1,580
14년 전 조회 1,578
14년 전 조회 1,593
14년 전 조회 1,398
14년 전 조회 2,434
14년 전 조회 2,217
14년 전 조회 1,643
14년 전 조회 1,477
14년 전 조회 2,548
14년 전 조회 1,906
14년 전 조회 1,736
14년 전 조회 1,468
14년 전 조회 2,176
14년 전 조회 4,461
14년 전 조회 3,090