有如下一张表:
user type
张三 A
张三 B
张三 C
李四 B
王五 B
赵六 C一个人可能对应多种type
现在要用一SQL语句统计type各有几人,即要统计的结果如下:
typeA typeB typeC
1 3 2请问语句要如何写呢?
非常感谢!
user type
张三 A
张三 B
张三 C
李四 B
王五 B
赵六 C一个人可能对应多种type
现在要用一SQL语句统计type各有几人,即要统计的结果如下:
typeA typeB typeC
1 3 2请问语句要如何写呢?
非常感谢!
解决方案 »
- 想问下,麻烦帮看看参数设置是否有问题,谢谢!
- 为啥分号隔开的两个语句在COMMAND窗口成功,在SQL窗口失败?
- solaris 8中配置好ORACLE后,关于JDBC的一个问题
- 数据类型可以是datetime么?
- 一个很简单的问题,大家帮个忙了
- 关于更新记录的行数
- 有关nls_lang的问题
- imp命令使用之前一定得先把表drop掉才行吗?
- 关于数据库连接的问题,急
- orcl 在包体里 调用其他的存储过程,然后返回值
- 这条语句中的project_id = :cProject_id and emp_id = :cEmp_id 里 =:表示什么意义?
- windows2003server+oracle10g用http://server:5500/em进入后进行备份时,出现主机身份证明问题.
select sum(case when type='A' then 1 else 0 end) typeA,
sum(case when type='B' then 1 else 0 end) typeB,
sum(case when type='C' then 1 else 0 end) typeC
from 表名
(select count(*) from tb where type = 'A') typeA,
(select count(*) from tb where type = 'B') typeB,
(select count(*) from tb where type = 'C') typeC
type内容故不固定无所谓