SELECT
a.PostTime As PostTime,
sum(case when a.PostId <> "" then 1 else 0 end) AS PostNumTotle,
sum(case when a.PostFloorId = 1 then 1 else 0 end) AS PostNumTopicTotle,
sum(case when a.PostFloorId <> 1 then 1 else 0 end) AS PostNumReplyTotle FROM
PostList a
GROUP BY
a.PostTime 我的意思是统计某个时间段的发帖人数发帖数量回帖数量等信息,但系统时间是到分秒的,这样统计出来的项太多,我只需要精确到小时即可,该如何表达?在线等,有答案后马上给分
a.PostTime As PostTime,
sum(case when a.PostId <> "" then 1 else 0 end) AS PostNumTotle,
sum(case when a.PostFloorId = 1 then 1 else 0 end) AS PostNumTopicTotle,
sum(case when a.PostFloorId <> 1 then 1 else 0 end) AS PostNumReplyTotle FROM
PostList a
GROUP BY
a.PostTime 我的意思是统计某个时间段的发帖人数发帖数量回帖数量等信息,但系统时间是到分秒的,这样统计出来的项太多,我只需要精确到小时即可,该如何表达?在线等,有答案后马上给分
SELECT
a.PostTime As PostTime,
sum(case when a.PostId <> "" then 1 else 0 end) AS PostNumTotle,
sum(case when a.PostFloorId = 1 then 1 else 0 end) AS PostNumTopicTotle,
sum(case when a.PostFloorId <> 1 then 1 else 0 end) AS PostNumReplyTotle FROM
PostList a
GROUP BY
convert(nvarchar(16),a.PostTime,120)
Convert( varchar(10), a.PostTime ,120) +' ' + Convert(varchar(2), DATEPART( Hour , a.PostTime )) As PostTime,
sum(case when a.PostId <> "" then 1 else 0 end) AS PostNumTotle,
sum(case when a.PostFloorId = 1 then 1 else 0 end) AS PostNumTopicTotle,
sum(case when a.PostFloorId <> 1 then 1 else 0 end) AS PostNumReplyTotle FROM
PostList a
GROUP BY
Convert( varchar(10), a.PostTime ,120) +' ' + Convert(varchar(2), DATEPART( Hour , a.PostTime ))
a.PostTime As PostTime,
sum(case when a.PostId <> "" then 1 else 0 end) AS PostNumTotle,
sum(case when a.PostFloorId = 1 then 1 else 0 end) AS PostNumTopicTotle,
sum(case when a.PostFloorId <> 1 then 1 else 0 end) AS PostNumReplyTotle FROM
PostList a
GROUP BY
convert(varchar(13),a.PostTime,120)精确到小时,varchar(13)就够了
convert(nvarchar(13),a.PostTime,120)+'时' as '时间段',
sum(case when a.PostId <> "" then 1 else 0 end) AS PostNumTotle,
sum(case when a.PostFloorId = 1 then 1 else 0 end) AS PostNumTopicTotle,
sum(case when a.PostFloorId <> 1 then 1 else 0 end) AS PostNumReplyTotle FROM
PostList a
GROUP BY
convert(nvarchar(13),a.PostTime,120)
DatePart(HH,a.PostTime) As PostTime,
sum(case when a.PostId <> '' then 1 else 0 end) AS PostNumTotle,
sum(case when a.PostFloorId = 1 then 1 else 0 end) AS PostNumTopicTotle,
sum(case when a.PostFloorId <> 1 then 1 else 0 end) AS PostNumReplyTotle FROM
PostList a
GROUP BY
DatePart(HH,a.PostTime)