我在选择 COUNT distinct 时遇到问题:我需要的答案是 6。时间差异 < 300Sec 计为 1。我的 sql :
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
我在选择 COUNT distinct 时遇到问题:我需要的答案是 6。时间差异 < 300Sec 计为 1。我的 sql :
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演示。