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,409
14년 전 조회 1,400
14년 전 조회 2,172
14년 전 조회 1,978
14년 전 조회 2,985
14년 전 조회 1,967
14년 전 조회 1,569
14년 전 조회 4,103
14년 전 조회 2,303
14년 전 조회 1,727
14년 전 조회 2,086
14년 전 조회 1,430
14년 전 조회 2,606
14년 전 조회 1,476
14년 전 조회 1,935
14년 전 조회 1,438
14년 전 조회 1,946
14년 전 조회 2,196
14년 전 조회 1,710
14년 전 조회 1,491
14년 전 조회 1,725
14년 전 조회 1,616
14년 전 조회 2,655
14년 전 조회 1,821
14년 전 조회 1,529
14년 전 조회 1,443
14년 전 조회 2,053
14년 전 조회 3,313
14년 전 조회 1,440
14년 전 조회 3,266
14년 전 조회 2,399
14년 전 조회 1,601
14년 전 조회 1,808
14년 전 조회 1,717
14년 전 조회 1,700
14년 전 조회 1,214
14년 전 조회 1,411
14년 전 조회 1,526
14년 전 조회 1,885
14년 전 조회 1,576
14년 전 조회 1,946
14년 전 조회 1,724
14년 전 조회 1,877
14년 전 조회 1,471
14년 전 조회 1,746
14년 전 조회 1,664
14년 전 조회 1,537
14년 전 조회 1,423
14년 전 조회 1,865
14년 전 조회 2,277
14년 전 조회 1,670
14년 전 조회 1,479
14년 전 조회 4,024
14년 전 조회 1,550
14년 전 조회 1,431
14년 전 조회 2,796
14년 전 조회 2,222
14년 전 조회 2,737
14년 전 조회 1,297
14년 전 조회 1,538
14년 전 조회 1,352
14년 전 조회 1,219
14년 전 조회 1,314
14년 전 조회 1,421
14년 전 조회 2,188
14년 전 조회 1,522
14년 전 조회 1,596
14년 전 조회 1,225
14년 전 조회 1,726
14년 전 조회 2,341
14년 전 조회 1,725
14년 전 조회 2,010
14년 전 조회 1,509
14년 전 조회 1,658
14년 전 조회 1,446
14년 전 조회 1,775
14년 전 조회 1,659
14년 전 조회 1,089
14년 전 조회 1,260
14년 전 조회 1,272
14년 전 조회 1,608
14년 전 조회 1,431
14년 전 조회 1,465
14년 전 조회 1,400
14년 전 조회 1,818
14년 전 조회 1,533
14년 전 조회 1,516
14년 전 조회 1,545
14년 전 조회 1,333
14년 전 조회 2,391
14년 전 조회 2,172
14년 전 조회 1,598
14년 전 조회 1,433
14년 전 조회 2,496
14년 전 조회 1,854
14년 전 조회 1,686
14년 전 조회 1,428
14년 전 조회 2,142
14년 전 조회 4,419
14년 전 조회 3,055