我在 SQL Server 中有一个数据库,列出了包含每个日期的海事事件。对于图表说明,我现在想编写一个 SQL 语句(用于 Visual Studio),它给出了每年的事件总数。
例子:
2009 2010(年 - X 轴)
4575 5432(年 - Y 轴)
X 轴的 SELECT 语句,我可以这样写
SELECT year1, year2 FROM (SELECT 2009 AS year1) AS a, ( SELECT 2010 AS year2) AS b
但是第二个呢?当我写类似的东西时:
SELECT totalyear1, totalyear2 FROM (SELECT COUNT(Reference) FROM STO.dbo.STOMaritimeIncidents WHERE [Incident date] = 2010 AS totalyear1) AS a, (SELECT COUNT(Reference) FROM STO.dbo.STOMaritimeIncidents WHERE [Incident date] = 2009 AS totalyear2) AS b
我收到类似“ Msg 156, Level 15, State 1, Line 1 Incorrect syntax near the keyword 'AS' 之类的错误。”
如果有人能给我一个解释或帮助我,我将不胜感激。非常感谢!