我需要获得每天的访客总数和&按日期订购
以下是日期示例
NoOfBooking VisitDate
2 2014-01-21 11:16:28.490
2 2014-01-20 06:12:46.983
1 2014-01-19 11:28:24.743
2 2014-01-19 02:43:46.867
1 2014-01-18 16:24:25.200
2 2014-01-05 20:20:29.597
2 2014-01-05 16:10:31.760
2 2014-01-02 10:23:52.333
2 2014-01-01 02:30:11.780
2 2013-12-31 10:02:01.083
由于带有日期的时间戳,我的输出几乎相同。我怎样才能获得仅基于日期的详细信息。
T-SQL查询
SELECT
SUM(NoOfBooking) AS Total, VisitDate
FROM
Booking
GROUP BY
NoOfBooking, VisitDate
ORDER BY
VisitDate DESC
更新:我也在下面试过它也不起作用。
SELECT
SUM(NoOfBooking) AS Total,
VisitDate
FROM
Booking
GROUP BY
NoOfBooking, CAST(VisitDate AS DATE)
ORDER BY
VisitDate DESC
答案 0 :(得分:1)
试试这个::
SELECT SUM(NoOfBooking) AS Total, VisitDate
FROM Booking GROUP BY NoOfBooking,
date(VisitDate) order by VisitDate DESC
答案 1 :(得分:1)
您可以将VisitDate转换为日期
SELECT SUM(NoOfBooking) AS Total, cast(VisitDate as Date) as VisitDate
FROM Booking
GROUP BY cast(VisitDate as Date)
order by cast(VisitDate as Date)
答案 2 :(得分:1)
试试这个:
SELECT SUM(NoOfBooking) AS Total, cast(VisitDate as date) as VisitDate
FROM Booking
GROUP BY cast(VisitDate as date)
order by VisitDate DESC
在NoOfBooking
中添加group by
会产生错误的结果......
答案 3 :(得分:0)
使用强制转换功能
select cast(visitdate as date) visdate, sum(NoOfBooking) total
from booking
group by cast(visitdate as date)
order by visdate
答案 4 :(得分:0)
您可以使用convert来获取日期部分。
SELECT SUM(NoOfBooking) AS Total, CONVERT(VARCHAR(10),VisitDate,111) AS VDATE
FROM Booking
GROUP BY CONVERT(VARCHAR(10),VisitDate,111)
ORDER BY VisitDateDESC