首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

asp sql 查询汇总结果,该怎么解决

2013-01-25 
asp sql 查询汇总结果例如表的结果如下:idtypeproname1上海大众POLO2上海大众桑塔纳20003一汽大众捷达4一

asp sql 查询汇总结果
例如表的结果如下:
id   type          proname
1   上海大众    POLO
2   上海大众    桑塔纳2000
3   一汽大众   捷达
4   一汽大众   CC
5   别克          凯越

现在是想实现查询结果中,只显示表中的type 以及 相同 type 有几辆,例如

上海大众 2
一汽大众 2
别克        1

请指点相关的SQL语句如何写,,
[解决办法]
select  type          ,count(1) 
from tb
group by type
[解决办法]
select type count(1) from 表 group by type
[解决办法]

引用:
select type count(1) from 表 group by type
少了个逗号
[解决办法]
CREATE TABLE TBA
(
id int,
type nvarchar(50),
proname nvarchar(50)
)
INSERT INTO TBA
select '1','上海大众','POLO' union all
select '2','上海大众','桑塔纳2000' union all
select '3','一汽大众','捷达' union all
select '4','一汽大众','CC' union all
select '5','别克','凯越' 

select type,count(type) from TBA group by type

[解决办法]
呵呵,,来晚了,楼主SQL语句应该刚接触哈,连分组函数都还不知道 ,得加强学习哦~
[解决办法]

select type ,count(1) as '数量'
from tb
group by type 

[解决办法]

if OBJECT_ID('car') is not null
drop table car
create table car
(
ID int,
type nvarchar(20),
proname nvarchar(20)
)
go
insert into car 
select 1,'上海大众','POLO' union all
select 2,'上海大众','桑塔纳2000' union all
select 3,'一汽大众','捷达' union all
select 4,'一汽大众','CC' union all
select 5,'别克',' 凯越'

select type,COUNT(type) from car
group by type 
order by type desc

热点排行