如何让在没有查询内容返回的情况下也显示一行数据
时间:2011-12-02
来源:互联网
例表:t1( hosname varchar2(20),hostype varhcar2(10) , cash number(12,2));
数据:(hostype数据为:区内,区外,省外,四类;数据随便列举,不代表实际意义)
hosname hostype cash
一院 区内 20000.00
二院 区内 30000.00
五院 省外 50000.00
select sum(cash),count(1) from t1 gorup by hostype
上面的情况,是只显示,存在hosttype的数据。但区外,和省内的数据,因为不存在所以没有。我现在想要结果:
区内 50000.00
区外 0.00
省内 0.00
省外 50000.00
如何实现?琢磨一上午了,没想出来...
数据:(hostype数据为:区内,区外,省外,四类;数据随便列举,不代表实际意义)
hosname hostype cash
一院 区内 20000.00
二院 区内 30000.00
五院 省外 50000.00
select sum(cash),count(1) from t1 gorup by hostype
上面的情况,是只显示,存在hosttype的数据。但区外,和省内的数据,因为不存在所以没有。我现在想要结果:
区内 50000.00
区外 0.00
省内 0.00
省外 50000.00
如何实现?琢磨一上午了,没想出来...
作者: guorui0526 发布时间: 2011-12-02
SQL code
------
1 区内 50000
2 区外 0
3 省外 50000
4 省内 0
with t1 as ( select '一院' hosname,'区内' hostype,20000.00 cash from dual union all select '二院' hosname,'区内' hostype,30000.00 cash from dual union all select '五院' hosname,'省外' hostype,50000.00 cash from dual ) select '区内',sum(decode(t1.hostype,'区内',cash,0)) sum1 from t1 union all select '区外',sum(decode(t1.hostype,'区外',cash,0)) from t1 union all select '省外',sum(decode(t1.hostype,'省外',cash,0)) from t1 union all select '省内',sum(decode(t1.hostype,'省内',cash,0)) from t1
------
1 区内 50000
2 区外 0
3 省外 50000
4 省内 0
作者: dws2004 发布时间: 2011-12-02
引用 1 楼 dws2004 的回复:
SQL code
with t1 as (
select '一院' hosname,'区内' hostype,20000.00 cash from dual union all
select '二院' hosname,'区内' hostype,30000.00 cash from dual union all
select '五院' hosname,'省外' hostype,50000……
SQL code
with t1 as (
select '一院' hosname,'区内' hostype,20000.00 cash from dual union all
select '二院' hosname,'区内' hostype,30000.00 cash from dual union all
select '五院' hosname,'省外' hostype,50000……
这个太具有针对性了。需要用group by 的。 是需要按定点做的统计信息. 而且要显示的数据列不只这几个。
只是出于特殊原因的考虑,不能把信息在这里提供完全...
作者: guorui0526 发布时间: 2011-12-02
测试数据:
SQL code
结果:
SQL code
CREATE TABLE T30 ( hosname VARCHAR2(20), hostype VARCHAR2(20), cash NUMBER(10) ); INSERT INTO T30 VALUES('一院', '区内', 20000); INSERT INTO T30 VALUES('二院', '区内', 30000); INSERT INTO T30 VALUES('五院', '省外', 50000);
结果:

作者: LuiseRADL 发布时间: 2011-12-02
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28