表
数据
select * from ware_info2
1
硫酸
1.0000
千克
2
盐酸
2.0000
千克
3
高锰酸钾
3.0000
吨
4
高锰酸钾
4.0000
千克
5
高锰酸钾
5000.0000
毫升
6
高锰酸钾
6.0000
升
7
高锰酸钾
7.0000
升
将毫升转换成升,吨转换成千克,汇总数据
select name,sum(
case
when unit='吨' then qty*1000
when unit='毫升' then qty/1000
else qty end),
case
when unit='吨' then '千克'
when unit='毫升' then '升'
when unit='升' then '升'
when unit='千克' then '千克'
end as unit
from ware_info2
group by name,case
when unit='吨' then '千克'
when unit='毫升' then '升'
when unit='升' then '升'
when unit='千克' then '千克'
end
结果:
高锰酸钾
3004
千克
硫酸
1
千克
盐酸
2
千克
高锰酸钾
18
升
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/28282660/viewspace-2154179/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/28282660/viewspace-2154179/
本文介绍了一种通过SQL查询来统一不同单位的化学品库存数据的方法。通过对原始数据进行单位换算,实现了库存量的有效汇总。例如,高锰酸钾的库存量总计为3004千克及18升。
5268

被折叠的 条评论
为什么被折叠?



