SQL命令建议

时间:2014-10-23 18:05:39

标签: mysql sql sql-server

如何在sql中使shipdate年大于2013年。这是我到目前为止的代码:

SELECT shipdate, COUNT(*)
  FROM dw.orderline
  GROUP BY shipdate
  ORDER BY 1;

3 个答案:

答案 0 :(得分:2)

这样的事情可以解决问题:

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

上的工作示例

答案 1 :(得分:1)

不应该

SELECT 
    shipdate, COUNT(*)
FROM 
    dw.orderline
WHERE 
    Year(shipdate)>2013
GROUP BY 
    shipdate

也应排除2013年的每个日期。或者我的问题解释不正确?

答案 2 :(得分:0)

正确查询:

SELECT shipdate, COUNT(*) ships_counter
  FROM dw.orderline
     WHERE shipdate > '01/01/2013'
        GROUP BY shipdate;