如何在SQL中使shipdate
年大于2013年。这是我到目前为止的代码:
SELECT shipdate, COUNT(*)
FROM dw.orderline
GROUP BY shipdate
ORDER BY 1;
最佳答案
这样的事情将达到目的:
SELECT shipdate, COUNT(*) AS SHIP_COUNT
FROM dw.orderline
WHERE shipdate >= '01/01/2013'
GROUP BY shipdate;
编辑:
根据您的评论:
SELECT YEAR(shipdate), COUNT(*) AS SHIP_COUNT
FROM dw.orderline
WHERE YEAR(shipdate) > 2013
GROUP BY shipdate
编辑2:
对于基于Oracle的SQL:
SELECT EXTRACT(year FROM shipdate), COUNT(*) AS SHIP_COUNT
FROM dw.orderline
WHERE EXTRACT(year FROM shipdate) > 2013
GROUP BY shipdate
请参阅有关SQL Fiddle here的工作示例