似乎无法找到语法错​​误

时间:2017-07-06 12:08:27

标签: data-warehouse

有人可以告诉我这里我做错了什么,我在附近的语法不正确。这个陈述怎么了?

INSERT INTO dbo.a1
    select x1 as id, x2 as enc_id, x3 as dev,x4 as mang, x4 as sre, x5 as phase,x6, x7, x8
    from
    (select *,
    row_number() over(partition by x2 order by x8)  as rank
    from ccsm.n9 where xx=1 and xx_pat=1 and xx_encz='Tesz')
     where rank=1;

1 个答案:

答案 0 :(得分:1)

您从未告诉我们您使用的SQL版本,但有一种可能性是您的派生表需要别名:

INSERT INTO dbo.a1
SELECT t.x1, t.x2, t.x3, t.x4, t.x4, t.x5, t.x6, t.x7, t.x8
FROM
(
    SELECT *,
        ROW_NUMBER() OVER (PARTITION BY x2 ORDER BY x8) AS rank
    FROM ccsm.n9
    WHERE xx = 1 and xx_pat = 1 and xx_encz = 'Tesz'
) t
WHERE t.rank = 1;

我知道Oracle强制执行派生表别名规则,也可能执行其他数据库。请注意,SELECT语句中的别名没有用处,因为只是插入了值。如果您希望两次插入x4,则只需重复两次。