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,252
14년 전 조회 1,239
14년 전 조회 2,022
14년 전 조회 1,810
14년 전 조회 2,828
14년 전 조회 1,809
14년 전 조회 1,405
14년 전 조회 3,943
14년 전 조회 2,141
14년 전 조회 1,569
14년 전 조회 1,932
14년 전 조회 1,282
14년 전 조회 2,438
14년 전 조회 1,331
14년 전 조회 1,777
14년 전 조회 1,278
14년 전 조회 1,778
14년 전 조회 2,035
14년 전 조회 1,543
14년 전 조회 1,343
14년 전 조회 1,572
14년 전 조회 1,451
14년 전 조회 2,483
14년 전 조회 1,660
14년 전 조회 1,368
14년 전 조회 1,297
14년 전 조회 1,875
14년 전 조회 3,147
14년 전 조회 1,293
14년 전 조회 3,084
14년 전 조회 2,250
14년 전 조회 1,437
14년 전 조회 1,647
14년 전 조회 1,557
14년 전 조회 1,547
14년 전 조회 1,093
14년 전 조회 1,253
14년 전 조회 1,367
14년 전 조회 1,726
14년 전 조회 1,432
14년 전 조회 1,795
14년 전 조회 1,554
14년 전 조회 1,725
14년 전 조회 1,316
14년 전 조회 1,587
14년 전 조회 1,501
14년 전 조회 1,381
14년 전 조회 1,256
14년 전 조회 1,706
14년 전 조회 2,107
14년 전 조회 1,511
14년 전 조회 1,338
14년 전 조회 3,860
14년 전 조회 1,394
14년 전 조회 1,284
14년 전 조회 2,621
14년 전 조회 2,064
14년 전 조회 2,556
14년 전 조회 1,136
14년 전 조회 1,381
14년 전 조회 1,204
14년 전 조회 1,064
14년 전 조회 1,166
14년 전 조회 1,263
14년 전 조회 2,044
14년 전 조회 1,374
14년 전 조회 1,457
14년 전 조회 1,078
14년 전 조회 1,581
14년 전 조회 2,178
14년 전 조회 1,595
14년 전 조회 1,874
14년 전 조회 1,347
14년 전 조회 1,508
14년 전 조회 1,310
14년 전 조회 1,619
14년 전 조회 1,497
14년 전 조회 944
14년 전 조회 1,125
14년 전 조회 1,111
14년 전 조회 1,455
14년 전 조회 1,294
14년 전 조회 1,343
14년 전 조회 1,269
14년 전 조회 1,682
14년 전 조회 1,376
14년 전 조회 1,395
14년 전 조회 1,420
14년 전 조회 1,212
14년 전 조회 2,266
14년 전 조회 2,027
14년 전 조회 1,476
14년 전 조회 1,310
14년 전 조회 2,373
14년 전 조회 1,725
14년 전 조회 1,575
14년 전 조회 1,298
14년 전 조회 2,024
14년 전 조회 4,285
14년 전 조회 2,925