如何返回10分钟内在同一天创建的记录?我想显示所有带有创建日期smalldatetime
的商品。
我试过这个,但它不起作用:
SELECT NAME,
TITLE,
CREATED
FROM TABLE
WHERE CREATEDBY = 'Billy'
GROUP BY NAME,
TITLE,
CREATED,
Datepart(YEAR, CREATED),
Datepart(MONTH, CREATED),
Datepart(DAY, CREATED),
Datepart(HOUR, CREATED),
( Datepart(MINUTE, CREATED) / 10 )
答案 0 :(得分:2)
根据我的理解。请尝试以下代码:
SELECT NAME,
TITLE,
CREATED
FROM TABLE
WHERE CreatedBy = 'Billy'
AND CREATED BETWEEN DATEADD(MINUTE,-10,GETDATE()) AND GETDATE();