我对SQL很新,我一直在进度数据库上使用SQL,我在下面有以下代码:
Select pub."GL_Table"."AccNum_Col", pub."GL_Table"."AccMnth_Col", Sum(pub."GL_Table"."Amount_Col"), ROUND((pub."GL_Table"."AccMnth_Col")/100,0) AS "Year", MOD(pub."GL_Table"."AccMnth_Col",100) As "Month"
FROM pub."GL_Table"
GROUP BY pub."GL_Table"."AccNum_Col", pub."GL_Table"."AccMnth_Col"
ORDER BY pub."GL_Table"."AccNum_Col", pub."GL_Table"."AccMnth_Col"
我只希望仅显示"Year"
2017
我尝试过以下(但收到错误):
Select * FROM (
Select pub."GL_Table"."AccNum_Col", pub."GL_Table"."AccMnth_Col", Sum(pub."GL_Table"."Amount_Col"), ROUND((pub."GL_Table"."AccMnth_Col")/100,0) AS "Year", MOD(pub."GL_Table"."AccMnth_Col",100) As "Month"
FROM pub."GL_Table"
GROUP BY pub."GL_Table"."AccNum_Col", pub."GL_Table"."AccMnth_Col"
ORDER BY pub."GL_Table"."AccNum_Col", pub."GL_Table"."AccMnth_Col"
)
WHERE "Year" = 2017
任何人都可以帮助我吗?
提前致谢
答案 0 :(得分:1)
虽然子查询是一种方法,但您也可以在where子句中引用计算。
Select pub."GL_Table"."AccNum_Col", pub."GL_Table"."AccMnth_Col", Sum(pub."GL_Table"."Amount_Col"), ROUND((pub."GL_Table"."AccMnth_Col")/100,0) AS "Year", MOD(pub."GL_Table"."AccMnth_Col",100) As "Month"
FROM pub."GL_Table"
WHERE ROUND((pub."GL_Table"."AccMnth_Col")/100,0) = 2017
GROUP BY pub."GL_Table"."AccNum_Col", pub."GL_Table"."AccMnth_Col"
ORDER BY pub."GL_Table"."AccNum_Col", pub."GL_Table"."AccMnth_Col"
答案 1 :(得分:0)
您缺少子查询别名。 order by子句应该在子查询之外应用。
group-timeout
答案 2 :(得分:0)
我猜你需要列别名和表别名。我对进步并不熟悉,但以下似乎更正确:
SELECT *
FROM (SELECT pub."GL_Table"."AccNum_Col", pub."GL_Table"."AccMnth_Col",
Sum(pub."GL_Table"."Amount_Col") as "Amount",
ROUND((pub."GL_Table"."AccMnth_Col")/100, 0) AS "Year",
MOD(pub."GL_Table"."AccMnth_Col", 100) As "Month"
FROM pub."GL_Table"
GROUP BY pub."GL_Table"."AccNum_Col", pub."GL_Table"."AccMnth_Col"
ORDER BY pub."GL_Table"."AccNum_Col", pub."GL_Table"."AccMnth_Col"
) ym
WHERE "Year" = 2017