gpt4 book ai didi

sql - 按日期选择数据并汇总数据 - SQL Server 2005

转载 作者:行者123 更新时间:2023-12-02 03:55:26 25 4
gpt4 key购买 nike

我来自 MySQL,并尝试在 SQL Server 2005 上编写 T-SQL,我发现它完全不同。

这是我想做的(使用 MySQL)

select sum(datapoint) as sum, date(mytimestamp) as date
from datalog
where datapoint = '27'
group by date

即获取按日期汇总和分组的数据列表。

最佳答案

<罢工>

<罢工>

sql server 2008被标记时的回答

select sum(datapoint) as [sum], CAST(mytimestamp AS DATE) as [date]
from datalog
where datapoint = '27'
group by CAST(mytimestamp AS DATE)

<罢工>

对于 SQL Server 2005

SELECT   CONVERT(VARCHAR(11), timestamp, 111) DATE, 
SUM(datapoint) totalDatapoint
FROM table1
GROUP BY CONVERT(VARCHAR(11), timestamp, 111)
ORDER BY DATE ASC

SQLFiddle Demo

关于sql - 按日期选择数据并汇总数据 - SQL Server 2005,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12887988/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com