我有选择COUNT的问题:我需要的答案是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
答案 0 :(得分: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 演示。