TYPE如果是1就去ums_fan表中查询fan_id属性;
如果是2就去ums_power表中查询unit_id属性;
如果是3就去ums_node表中查询node_id属性。
td_alarm_status通过did列与其他3张表的solitid关联。
如何进行type的判断查询出td_alarm_status和另外一列(***_id)的联合属性???
求高手指导!!!
5 个解决方案
#1
有没有高人啊!!!
#2
#3
select a.*,
case a.TYPE when 1 then b.fan_id when 2 then c.unit_id when 3 then d.node_id end as xid
from td_alarm_status a left join ums_fan b on b.solitid=a.did
left join ums_power c on c.solitid=a.did
left join ums_node d on d.solitid=a.did
#4
------------方法二----------------
,with t(tb_id, solitid, xid) as
(
select 1, solitid, fan_id from ums_fan union
select 2, solitid, unint_id from ums_power union
select 3, solitid, node_id from ums_node
)
select a.*, t.xid
from td_alarm_status a left join t on t.tb_id=a.TYPE and t.solitid=a.did
#5
写的真好!按照你说的我运行成功了!谢谢了,分给你了!!
#1
有没有高人啊!!!
#2
#3
select a.*,
case a.TYPE when 1 then b.fan_id when 2 then c.unit_id when 3 then d.node_id end as xid
from td_alarm_status a left join ums_fan b on b.solitid=a.did
left join ums_power c on c.solitid=a.did
left join ums_node d on d.solitid=a.did
#4
------------方法二----------------
,with t(tb_id, solitid, xid) as
(
select 1, solitid, fan_id from ums_fan union
select 2, solitid, unint_id from ums_power union
select 3, solitid, node_id from ums_node
)
select a.*, t.xid
from td_alarm_status a left join t on t.tb_id=a.TYPE and t.solitid=a.did
#5
写的真好!按照你说的我运行成功了!谢谢了,分给你了!!