1

我正在使用 Microsoft SQL Database Management Studio,它不允许我使用 strftime() 函数来运行查询。我必须按月创建一个表,每个月都有新用户和取消订阅者。

这就是我本质上造成错误的原因:

SELECT strftime('%m', createddate) AS 'Month', COUNT(createddate) AS 'Subscribers',
       COUNT(dateunsubscribed) AS 'UNsubscribers'
FROM subscriber
GROUP BY 1
ORDER BY 1;

如果没有,我怎么能运行这个查询,strftime()或者我怎样才能开始strftime()工作?

4

1 回答 1

3

strftime是一个中不可用。

对于这个简单的用例(从日期中提取一个月),您可以使用month

SELECT   MONTH(createddate) AS [Month], 
         COUNT(createddate) AS [Subscribers],
         COUNT(dateunsubscribed) AS [UNsubscribers]
FROM     subscriber
GROUP BY 1
ORDER BY 1;

编辑:
为了解决评论中的问题,该group by子句不像该子句那样采用序数order by。您需要指定要分组的表达式:

SELECT   MONTH(createddate) AS [Month], 
         COUNT(createddate) AS [Subscribers],
         COUNT(dateunsubscribed) AS [UNsubscribers]
FROM     subscriber
GROUP BY 1
ORDER BY MONTH(createddate);
于 2018-08-14T15:50:49.747 回答