'strftime'不是公认的内置函数名称 [英] 'strftime' is not a recognized built-in function name

查看:571
本文介绍了'strftime'不是公认的内置函数名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am using Microsoft SQL Database Management Studio and it will not allow me to use the strftime() function to run a query. I have to create a table by months with new users and unsubscribers for each month.

这基本上就是我产生错误的原因:

This is what I had essentially which creates the error:

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

在没有strftime()的情况下我还能如何运行该查询?或者如何使strftime()正常工作?

how else could I run this query without strftime() or how can I get strftime() to work?

推荐答案

strftime是.

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

For this simple usecase (extracting a month from a date), you could user 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子句那样使用序数.您需要指定要分组的表达式:


To address the question in the comment, the group by clause doesn't take an ordinal like the order by clause does. You'll need to specify the expression you want to group by:

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

这篇关于'strftime'不是公认的内置函数名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆