我正在尝试统计昨天每小时发生的所有交易。我不希望今天进行交易。但我似乎无法在这种情况下获得正确的代码。
到目前为止我的代码:
SELECT CAST(TransDT as DATE) as 'TransDate'
,CAST(DATEPART(Hour, TransDT) as varchar) + ':00' as 'Hour'
,LaneID
,Direction
,COUNT(*) as 'Ct'
FROM Traffic_analysis
WHERE TransDT >= DATEADD (DAY, -1 , SYSDATETIME())
AND TransDT < CAST(DATEPART(DAY, SYSDATETIME()) as int) --This is the faulty line.
GROUP BY CAST(TransDT as DATE), DATEPART(Hour, TransDT), LaneID, Direction
ORDER BY CAST(TransDT as DATE) ASC
如果我注释掉整个错误行,我也会得到昨天和今天的结果。我只需要昨天的结果。
我要做的是显示一个带有图表的报告,该图表显示每小时、每条车道、每个方向的交通量。将所有 NB 流量放在一个列中,将所有 SB 流量放在另一列中会更好。也许是 UNION 加入?