gpt4 book ai didi

SQL Sum 当天的多个值

转载 作者:行者123 更新时间:2023-12-03 23:28:59 25 4
gpt4 key购买 nike

这是我的 table

TIME                     Status
2012-11-15 8:30:00.000 "WAS_FLOW"
2012-11-15 9:00:00.000 "WAS_FLOW"
2012-11-15 10:30:00.000 "H2_FLOW"
2012-11-11 12:14:00.00 "O23HZ_FLOW"
2012-11-11 8:00.00.000 "AZ_FLOW"
2012-11-12 9:00.000 "BZ_FLOW"

我希望我的结果显示:

TIME         "WAS FLOW"    
2012-11-11 0
2012-11-12 0
2012-11-15 2

最佳答案

这里的其他答案都有轻微的故障。我希望这是一个开箱即用为您服务的工具。

SELECT
DATEADD(DAY, DATEDIFF(DAY, 0, [time]), 0) AS [date],
SUM(CASE WHEN status = 'WAS_FLOW' THEN 1 ELSE 0 END) AS [count]
FROM
yourTable
GROUP BY
DATEADD(DAY, DATEDIFF(DAY, 0, [time]), 0)

关于SQL Sum 当天的多个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13458638/

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