我有列的表格:集料的日期的SQL Server 2005
ID_LOG (this is the pk) | TS (type=datetime) | VALUE (type=double) | ID_CHANNEL (unique).
该表记录值形成每15分钟不同的渠道。这些值取自一些计数器,因此它们一直在增加。
现在我想知道特定频道去年每一天的最大值和最小值(因此净差)之间的差异。
喜欢的东西:
SELECT MAX(T1.value) - MIN(T1.value), T1.ts
FROM dbo.[LOG] as T1
WHERE T1.ts > DATEADD(year, -1, GETDATE()) and
T1.ID_CHANNEL=x //[x being the channel i want]
GROUP BY SOMEDATEFUNCITON(T1.ts) //[SOMEDATEFUNCTION is the function that groups results by date not taking in consideration the time of timestamp but only year-month-day]
我不在乎efficency我将每年做这个查询只有一次或两次。 这可能吗?你会怎么做?
非常感谢!
这实际上甚至在SQL Server 2005上也有诀窍。非常感谢! – andreapier