有这样一张表 a,我想实现不同的温度对应不同的阀门输出,关系如表b,如何把表b的对应关心更新到表一里面,谢谢高手指点
表a
机组 温度 设定温度 阀门输出
机组1 16.5 17 0.5
机组2 16.2 17 0.8
机组3 16.3 17 0.7
机组4 16 17 1
机组5 16.4 17 0.6
机组6 16.2 17 0.8
机组7 16.5 17 0.5
机组8 16.5 17 0.5
机组9 16.5 17 0.5
机组10 16.5 17 0.5
表b 温度 阀门输出
17 0.5
10 0.4
9 0.2
8 0.1
1 0.01
------解决思路----------------------
如果我没理解错误的话,你是想 低于1 度的用 0.01 阀门输出, 1< X<=8 的 用 0.1 阀门输出, 。。。。。。?
可以先处理表A的实际温度到范围,然后连接。
; with tb as
(
select 机组, 设定温度, 阀门输出,
case
when 温度 >= 17 then 17
when 温度 >= 10 and 温度 < 17 then 10
when 温度 >= 9 and 温度 < 10 then 9
when 温度 >= 8 and 温度 < 9 then 8
when 温度 < 8 then 1 end as 温度
from 表a
)
select t1.机组, t1. 温度, t1.设定温度, t2.阀门输出
from tb as t1
left join 表b as t2
on t1.温度 =t2.温度