我已经发布了下面的SQL语句:
SELECT GATNR
,GITNO
,GBANO
,MAX (CASE WHEN GATID = 'GR' THEN GATVN ELSE NULL END) AS GR
,MAX (CASE WHEN GATID = 'SZ' THEN GATVN ELSE NULL END) AS SZ
FROM TABLEA AS X
INNER JOIN
(
(
SELECT MAX(GATNR)AS GATNR,GBANO
FROM TABLEA
GROUP BY GBANO
)
INNER JOIN
(
SELECT *
FROM TABLEB
) AS B
ON B.TBANO = GBANO
) AS Y
ON Y.GATNR = X.GATNR
WHERE
GITNO LIKE 'F%'
GROUP BY X.GATNR, X.GITNO, X.GBANO
由于某种原因,它无法运行&生成以下错误消息:
消息156,级别15,状态1,行13关键字附近的语法不正确 '内部'。
消息156,级别15,状态1,行16错误的语法附近 关键字'AS'。
我无法解决它。有人可以帮我纠正这个陈述吗?
答案 0 :(得分:1)
我想你想要这样的东西:
SELECT GATNR
,GITNO
,GBANO
,MAX (CASE WHEN GATID = 'GR' THEN GATVN ELSE NULL END) AS GR
,MAX (CASE WHEN GATID = 'SZ' THEN GATVN ELSE NULL END) AS SZ
FROM TABLEA AS X
INNER JOIN
(SELECT MAX(GATNR)AS GATNR,GBANO
FROM TABLEA
GROUP BY GBANO
) AS C
ON C.GBANO = X.GBANO AND C.GATNR = X.GATNR
INNER JOIN
TABLEB AS B
ON B.TBANO = X.GBANO
WHERE
GITNO LIKE 'F%'
GROUP BY X.GATNR, X.GITNO, X.GBANO
但是,如果没有看到你的架构,很难知道。
答案 1 :(得分:0)
尝试更改此内容:
SELECT MAX(GATNR)AS GATNR,GBANO
要:
SELECT MAX(GATNR) AS GATNR,GBANO
(我在“MAX(GATNR)”和“AS”之间添加了一个空格)。我不确定这是否会解决问题。