declare @a table(id int,city_id int,title varchar(10)) insert into @a select 1,1,'xx' union all select 2,2,'xxx' union all select 3,3,'xxxx' union all select 4,1,'xxx' union all select 5,2,'xxxx' union all select 6,2,'xxxx' select * from @a select distinct city_id,count(title) as [count(title)] from @a group by city_id;
declare @a table(id int,city_id int,title varchar(10))
insert into @a
select 1,1,'xx' union all
select 2,2,'xxx' union all
select 3,3,'xxxx' union all
select 4,1,'xxx' union all
select 5,2,'xxxx' union all
select 6,2,'xxxx' select * from @a
select distinct city_id,count(title) as [count(title)] from @a group by city_id;