一张表,有字段type(类型)和stuts(状态)等字段,现在需要count某type所有记录和该type下某一stuts的记录
有办法用一条sql写出来吗?
有办法用一条sql写出来吗?
解决方案 »
- oracle在job的使用问题
- 急!哥们的分全豁出去了只求一oracle命令行建库的方法 在线狂等
- 数据库赋值,怎么做?
- 菜鸟100分求助,oracle入门学习?
- 这是求一天每个区域的上班时间数.现在我想求按每个月每个分区的平均小时数应如何写 ????
- C++用Ado连接Oracle的问题
- 请教:oracle中有求两个日期之间相差的自然月吗?
- 关于ORACLE的存储和备份:
- oracle 9i 点击enterprise manager console 操作系统没有反应
- 两张表存在一对多关系,如何建立视图?
- Orcle内存不足帮忙解决一下
- oracle数据库保存fcketitor编辑控件为clob字段出错
union all
select type , stuts , count(*) from tb group by type , stuts select type , '' stuts , count(1) from tb group by type , stuts
union all
select type , stuts , count(1) from tb group by type , stuts 如果要排序,自己加order by
select t.type,count(*),max(t.stuts)
from test2 t
group by t.type但如果是随机取的话我还不也不知道用哪个函数分组,但如果加了条件的话可以用下面的语句:
select a.type,a.num,b.stuts
from
(select type,count(*) num from test2 where type='001' group by type ) a,
(select type,stuts from test2 where type='001' and rownum<=1) b
where a.type=b.type
select count(*) as "被关注类型总记录数",sum(decode(stuts,'你关注的状态1的值',1,0)) as "状态1记录数",sum(decode(stuts,'你关注的状态2的值',1,0)) as "状态2记录数" from yourtable where type = '你关注的类型的值';