求最简单的SQL语句解决方案
一个有关单位换算更新表的问题
有两张表的内容分别为:
select * from table1
value unit
------ -------
136.29 兆瓦
619.33 千瓦
17305870.00 瓦特
56290.00 瓦特
2356.00 千瓦
select * from table2
unit1 unit2 rate
----- ----- ----
瓦特 千瓦 0.001
兆瓦 千瓦 1000
其中table1为数值表,但是单位不统一,他需要根据table2中的换算关系来换算成统一单位。
比如后面是“兆瓦”单位的,前面的数值就乘以1000,如果是“瓦特”的就乘以0.001(即除以1000)
想要得到的结果为:
value unit
------ -------
136000.29 千瓦
619.33 千瓦
17305.87 千瓦
56.29 千瓦
2356.00 千瓦
求SQL语句,越简单越好
SQL code:
select
a.[value]*b.[rate] as [value],b.unit
from
a,b
where
a.unit1=b.unit1
SQL code:
--> 测试数据:[table1]
if object_id('[table1]') is not null drop table [table1]
create table [table1]([value] numeric(10,2),[unit] varchar(4))
go
insert [table1]
select 136.29,'兆瓦' union all
select 619.33,'千瓦' union all
select
相关问答:
今天做了一个存储过程 环境是SQL2000数据库
大致如下
建立临时表
定义员工游标
循环员工(属于1个公司)
......
我是在toad中输入下段sql
declare
TYPE test_rec IS record(
code varchar(10),
name varchar(30)
);
v_book test_rec;
......
如何在SQL2005中设定定时作业,比如说定时清理某些表的数据,
或者是定时的将某些表的数据导出excel!
在线等待,急急急,最好是详细步骤!
之前我做的作业有点问题!
帮UP
参考:http://hi.baidu.com/toiota ......
tab1 字段:billdate,goodsid,incount,inmoney,outcount,outmoney,endprice,endcount,endamt
tab2 字段:goodsid,goodskind(商品类型)
tab3 字段:goodskind(商品类型),kindname
结果:
得到商品类型在一段时间 ......