【问题标题】:'strftime' is not a recognized built-in function name“strftime”不是可识别的内置函数名
【发布时间】:2018-08-14 15:45:06
【问题描述】:

我正在使用 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() 工作?

【问题讨论】:

  • 那是因为strftime() 不是 SQL Server 函数。提示:改为查看formats

标签: sql select strftime database-management


【解决方案1】:

strftime 函数,在 Microsoft 的 中不可用。

对于这个简单的用例(从日期中提取一个月),您可以使用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);

【讨论】:

  • 我现在一直收到这个错误:每个 GROUP BY 表达式必须至少包含一个不是外部引用的列。
  • @Klew 这是一个不同的问题。请参阅我的更新答案以获取解决方案。
猜你喜欢
  • 2017-10-19
  • 2014-06-12
  • 2014-01-25
  • 2017-04-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多