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,379
14년 전 조회 1,380
14년 전 조회 2,148
14년 전 조회 1,943
14년 전 조회 2,959
14년 전 조회 1,935
14년 전 조회 1,542
14년 전 조회 4,077
14년 전 조회 2,282
14년 전 조회 1,699
14년 전 조회 2,060
14년 전 조회 1,403
14년 전 조회 2,573
14년 전 조회 1,456
14년 전 조회 1,908
14년 전 조회 1,413
14년 전 조회 1,915
14년 전 조회 2,166
14년 전 조회 1,685
14년 전 조회 1,455
14년 전 조회 1,690
14년 전 조회 1,584
14년 전 조회 2,625
14년 전 조회 1,787
14년 전 조회 1,509
14년 전 조회 1,419
14년 전 조회 2,025
14년 전 조회 3,295
14년 전 조회 1,414
14년 전 조회 3,227
14년 전 조회 2,373
14년 전 조회 1,567
14년 전 조회 1,780
14년 전 조회 1,695
14년 전 조회 1,674
14년 전 조회 1,190
14년 전 조회 1,378
14년 전 조회 1,499
14년 전 조회 1,859
14년 전 조회 1,547
14년 전 조회 1,907
14년 전 조회 1,688
14년 전 조회 1,844
14년 전 조회 1,445
14년 전 조회 1,715
14년 전 조회 1,640
14년 전 조회 1,513
14년 전 조회 1,390
14년 전 조회 1,832
14년 전 조회 2,251
14년 전 조회 1,643
14년 전 조회 1,457
14년 전 조회 3,996
14년 전 조회 1,519
14년 전 조회 1,405
14년 전 조회 2,767
14년 전 조회 2,193
14년 전 조회 2,705
14년 전 조회 1,275
14년 전 조회 1,517
14년 전 조회 1,324
14년 전 조회 1,200
14년 전 조회 1,280
14년 전 조회 1,393
14년 전 조회 2,165
14년 전 조회 1,496
14년 전 조회 1,573
14년 전 조회 1,202
14년 전 조회 1,697
14년 전 조회 2,311
14년 전 조회 1,700
14년 전 조회 1,988
14년 전 조회 1,486
14년 전 조회 1,640
14년 전 조회 1,420
14년 전 조회 1,751
14년 전 조회 1,626
14년 전 조회 1,064
14년 전 조회 1,236
14년 전 조회 1,245
14년 전 조회 1,585
14년 전 조회 1,414
14년 전 조회 1,449
14년 전 조회 1,377
14년 전 조회 1,791
14년 전 조회 1,502
14년 전 조회 1,501
14년 전 조회 1,520
14년 전 조회 1,308
14년 전 조회 2,371
14년 전 조회 2,151
14년 전 조회 1,577
14년 전 조회 1,413
14년 전 조회 2,469
14년 전 조회 1,834
14년 전 조회 1,667
14년 전 조회 1,409
14년 전 조회 2,122
14년 전 조회 4,408
14년 전 조회 3,039