Sql server 如何在两个日期之间每月检查状况
我正在为一个项目处理stack exchange数据库。(Sql server 如何在两个日期之间每月检查状况,sql-server,Sql Server,我正在为一个项目处理stack exchange数据库。( 我想知道的前10名用户谁有张贴每个月之间有在数据库中注册。 我已经试过了,但是我迷路了: SELECT TOP 10 Propriétaire FROM (SELECT count(Mois) AS nbMoisPosté, datediff(month, création, getdate()) AS nbMoisTotal, Propriétaire FROM
我想知道的前10名用户谁有张贴每个月之间有在数据库中注册。 我已经试过了,但是我迷路了:
SELECT TOP 10
Propriétaire
FROM
(SELECT
count(Mois) AS nbMoisPosté,
datediff(month, création, getdate()) AS nbMoisTotal,
Propriétaire
FROM
(SELECT
count(Posts.Id) AS nbPosts,
month(Posts.creationDate) AS Mois,
year(Posts.creationDate) AS Année
Posts.ownerUserId AS Propriétaire,
Users.creationDate AS création
FROM
Posts, Users
WHERE
Users.Id = Posts.ownerUserId
GROUP BY
Posts.ownerUserId,
Mois,
Année,
création) compte
GROUP BY
datediff(month, création, getdate()),
Propriétaire) nbMois
WHERE nbMoisPosté = nbMoisTotal
它不起作用(语法错误),但我不理解我的错误。
谢谢。尝试更正这些问题 请确保您发布了错误消息
SELECT TOP 10
Propriétaire
FROM
(
SELECT
count(Mois) AS nbMoisPosté,
datediff(month, création, getdate()) AS nbMoisTotal,
Propriétaire
FROM
(
SELECT
count(Posts.Id) AS nbPosts,
month(Posts.creationDate) AS Mois,
year(Posts.creationDate) AS Année --MISSING COMMA
Posts.ownerUserId AS Propriétaire,
Users.creationDate AS création
FROM
Posts,
Users
WHERE
Users.Id = Posts.ownerUserId
GROUP BY
Posts.ownerUserId,
Mois, --GROUP BY THE FUNCTION month(Posts.creationDate)
Année, --GROUP BY THE FUNCTION year(Posts.creationDate)
création
) compte
GROUP BY
datediff(month, création, getdate()),
Propriétaire
) nbMois
WHERE
nbMoisPosté = nbMoisTotal
请共享错误错误:“Posts”附近的语法不正确”清除代码,您将看到Posts附近缺少逗号。有趣的是,错误消息是如何工作的……哪个单词发布的?你在
年(Posts.creationDate)之后缺少了一个逗号,作为Année
的初学者。。。第二,去掉那些旧式的连接。在ORDERBY子句中只能使用这样的列名,而不能在GROUP BY子句中使用列名,ORDERBY子句有很多问题。现在是工作了别忘了勾选你选择的答案。