gpt4 book ai didi

sql - 如何选择不同的计数?

转载 作者:行者123 更新时间:2023-12-04 18:09:48 25 4
gpt4 key购买 nike

我在选择 COUNT distinct 时遇到问题:我需要的答案是 6。时间差 < 300Sec 计为 1。我的数据库:

SELECT COUNT(DISTINCT(cast([Date] as date) + cast([time] as datetime)))
FROM [Table1]WHERE [DATE] = '2013-06-22'
AND ErrCode = 'Scrubber Failure'AND Frequency = 1

最佳答案

已更新

SELECT COUNT(DISTINCT 
ROUND(CONVERT(DECIMAL(20, 4),
DATEDIFF(minute,
CONVERT(datetime, '2013-01-01 00:00:00', 120),
CONVERT(datetime, date + ' ' + time, 120))) / 5, 0)) n
FROM table1
WHERE date = '2013-06-22'
AND errcode = 'Scrubber Failure'
AND frequency = 1

输出:

| N |-----| 6 |

这是 SQLFiddle 演示。

关于sql - 如何选择不同的计数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17258340/

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