-1
我想通過不同站點上的車輛註冊牌進行分組,車輛進入站點的次數是多少次,我正在使用SQL Server 2008 R2。按SQL Server中3列的範圍組
我的數據是這樣的:
Streetname vrm 0-9 10-19 19-20
Ebbw vale xyz 1 15 30
Peel Center M89GW 6 35 45
這是我的查詢:
Select
t.t_street_name, COUNT(t_vrm) as MultipleEntries
from
(select
case
when count(t_vrm) between 0 and 9 then '0-9'
when count(t_vrm) between 10 and 19 then '10-19'
when count(t_vrm) between 20 and 29 then '20-29'
when count(t_vrm) between 30 and 39 then '30-39'
when count(t_vrm) between 40 and 49 then '40-49'
when count(t_vrm) between 50 and 59 then '50-59'
end as t_vrm
from
[ICPS].[dbo].[tickets]) t
where
convert (datetime, t.t_date_time_issued, 101) between convert(datetime, '2015/11/15', 101) and convert (datetime, '2015/12/17', 101)
Group By
t_vrm, t.t_street_name
我得到這個錯誤
無效的列名
t_street_name
。
,你能否告訴了' [ICPS]。[dbo]。[門票]'結構? –
你的查詢是搞砸了。你在沒有'group by'的子查詢中有count()'。然後你在外部查詢中有'group by'。所以,有很多問題。你想做什麼? –