-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'。所以,有很多问题。你想做什么? –