我有一个适用于Oracle数据库的Oracle查询。但是当我试图将其转移到MySQL时,我有语法错误,我无法理解错误的位置。
Oracle查询:
DELETE FROM tec_valid_codes
WHERE code IN
(SELECT a.oldacctnbr
FROM tec_onoff_file a,
tec_onoff_file b,
tec_valid_codes c
WHERE a.curracctnbr = b.curracctnbr
AND a.oldacctnbr <> b.oldacctnbr
AND a.transtype = 'COMB'
AND b.transtype = 'COMB'
AND a.oldacctnbr = c.code
MINUS
SELECT MAX (c.oldacctnbr)
FROM tec_valid_codes tvc,
(SELECT a.oldacctnbr, a.curracctnbr
FROM tec_onoff_file a, tec_onoff_file b
WHERE a.curracctnbr = b.curracctnbr
AND a.oldacctnbr <> b.oldacctnbr
AND a.transtype = 'COMB'
AND b.transtype = 'COMB') c
WHERE tvc.code = c.oldacctnbr
GROUP BY curracctnbr);
我的MySQL查询,无效:
DELETE FROM tec_valid_codes vc
WHERE vc.code IN
(SELECT t1.oldacctnbr FROM
(SELECT a.oldacctnbr
FROM tec_onoff_file a,
tec_onoff_file b,
tec_valid_codes c
WHERE a.curracctnbr = b.curracctnbr
AND a.oldacctnbr <> b.oldacctnbr
AND a.transtype = 'COMB'
AND b.transtype = 'COMB'
AND a.oldacctnbr = c.code) as `t1`
WHERE t1.oldacctnbr NOT IN
(SELECT MAX(c.oldacctnbr)
FROM tec_valid_codes tvc,
(SELECT a.oldacctnbr, a.curracctnbr
FROM tec_onoff_file a, tec_onoff_file b
WHERE a.curracctnbr = b.curracctnbr
AND a.oldacctnbr <> b.oldacctnbr
AND a.transtype = 'COMB'
AND b.transtype = 'COMB') as `c`
WHERE tvc.code = c.oldacctnbr)
GROUP BY vc.curracctnbr);
我在这一行有错误:
'vc
WHERE vc.code IN
(SELECT t1.oldacctnbr FROM
(SELECT a.oldacctn'
我在这里看不到语法错误。我哪里错了?我的MySQL查询是否正常工作?
已编辑:我的解决方案:
DELETE FROM tec_valid_codes
WHERE code IN
(SELECT t1.oldacctnbr FROM
(SELECT a.oldacctnbr
FROM tec_onoff_file a,
tec_onoff_file b,
tec_valid_codes c
WHERE a.curracctnbr = b.curracctnbr
AND a.oldacctnbr <> b.oldacctnbr
AND a.transtype = 'COMB'
AND b.transtype = 'COMB'
AND a.oldacctnbr = c.code) as `t1`)
AND code NOT IN
(SELECT t2.oldcode FROM
(SELECT MAX(c.oldacctnbr) as oldcode
FROM tec_valid_codes tvc,
(SELECT a.oldacctnbr, a.curracctnbr
FROM tec_onoff_file a, tec_onoff_file b
WHERE a.curracctnbr = b.curracctnbr
AND a.oldacctnbr <> b.oldacctnbr
AND a.transtype = 'COMB'
AND b.transtype = 'COMB') as `c`
WHERE tvc.code = c.oldacctnbr
GROUP BY curracctnbr) as `t2`);
查询是否正确?
答案 0 :(得分:0)
你最后(至少)犯了一个小错误:
GROUP BY vc.curracctnbr
应该来自t1:
GROUP BY t1.curracctnbr