【【【请教大神们一条SQL语句】】】

jauia 2011-08-04 07:58:57
表:city

id | city_id | title
1 | 1 | xx
2 | 2 | xxx
3 | 3 | xxxxx
4 | 1 | x x x
5 | 2 | x x x x
6 | 2 | x x x x

要想的显示结果是:
city_id | count(title)
1 | 2
2 | 3
3 | 1

根据这张表,显示出不同city_id的title个数.

请大神们指教!
...全文
77 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复

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;
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 jauia 的回复:]
郁闷,刚发完问题,自己写出来了..
[/Quote]
jauia 2011-08-04
  • 打赏
  • 举报
回复
郁闷,刚发完问题,自己写出来了..

57,062

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧