(MeterOrigValue)表里有六个列,分别是 departmentid(部门id),fid(水电表示id),useqty(水电使用数),time(采集时间),wprice(水单价),
electPrice(电单价) fid里分2种:1表示水; 2表示电 select departmentid, case when fid='1' then sum(cast (useqty as decimal(8,2)))
else '0' end as 用水量,case when fid='15' then sum(cast (useqty as decimal(8,2)))
else '0' end as 用电量
from MeterOrigValue group by fid,departmentid这样出来的数据会是
部门 用水量 用电量
1 0 25
2 12 0
3 33 0
1 12 0
2 0 15
3 0 66想请问下有没有办法把用水,用电合并到一行,显示结果变成
部门 用水量 用电量
1 12 25
2 12 15
3 33 66
electPrice(电单价) fid里分2种:1表示水; 2表示电 select departmentid, case when fid='1' then sum(cast (useqty as decimal(8,2)))
else '0' end as 用水量,case when fid='15' then sum(cast (useqty as decimal(8,2)))
else '0' end as 用电量
from MeterOrigValue group by fid,departmentid这样出来的数据会是
部门 用水量 用电量
1 0 25
2 12 0
3 33 0
1 12 0
2 0 15
3 0 66想请问下有没有办法把用水,用电合并到一行,显示结果变成
部门 用水量 用电量
1 12 25
2 12 15
3 33 66
解决方案 »
- 小菜鸟的问题,求各位大哥大姐指教
- 请问怎样的索引可以使"like"查询加快
- sql server 2005 连接数据库
- 健列信息不足或不正确,更新影响过多的列
- BOM死循环 超级难!!!!! 欢迎大仙
- 为什么装了sql2k sp3后 ,不能正常启动查询分析器和企业管理器,并且cpu占用时而100% ?
- 写福彩漏期数问题.
- 一个有关数据导入的问题!!(从文本文件导数据时,如何保证不会导入重复记录?)
- VFP中的双字节字符函数
- 如何Ms SQL Sever 的 EnterpriseManager 中,在设计一个字段的缺省值时,引用本行的其他字段的数据。
- 求 用sql statement取代cursor的問題 急...
- sql2008数据库同步并发的问题
else '0' end) as 用水量,sum(case when fid='15' then cast (useqty as decimal(8,2))
else '0' end) as 用电量
from MeterOrigValue group by departmentid
else '0' end) as 用水量,sum(case when fid='15' then cast (useqty as decimal(8,2))
else '0' end) as 用电量
from MeterOrigValue group by departmentid
else '0' end )as 用水量,sum(case when fid='15' then sum(cast (useqty as decimal(8,2)))
else '0' end) as 用电量
from MeterOrigValue
group by fid,departmentid