sqlserver语句中 case when then else X end
selectnode_treeview.node_name,(casewhen(temperature>='100')then'1'elsenullend),(casew...
select node_treeview.node_name,(case when (temperature>='100') then'1' else null end),(case when (battery>='100')then'2' else null end),(case when (fengsu>='100') then'3'else null end),
(case when (shidu>='100') then '4' else null end),(case when (wasi>='1000') then'5'else null end),(case when (fenchen>='100')then'6' else null end) from node_latest inner join node_treeview on node_latest.ll_addr=node_treeview.ll_addr
如何让case 。。when中不满足条件的就不查询出来? 展开
(case when (shidu>='100') then '4' else null end),(case when (wasi>='1000') then'5'else null end),(case when (fenchen>='100')then'6' else null end) from node_latest inner join node_treeview on node_latest.ll_addr=node_treeview.ll_addr
如何让case 。。when中不满足条件的就不查询出来? 展开
1个回答
展开全部
SELECT NODE_TREEVIEW.NODE_NAME,
(CASE
WHEN (TEMPERATURE >= '100') THEN
'1'
ELSE
NULL
END),
(CASE
WHEN (BATTERY >= '100') THEN
'2'
ELSE
NULL
END),
(CASE
WHEN (FENGSU >= '100') THEN
'3'
ELSE
NULL
END),
(CASE
WHEN (SHIDU >= '100') THEN
'4'
ELSE
NULL
END),
(CASE
WHEN (WASI >= '1000') THEN
'5'
ELSE
NULL
END),
(CASE
WHEN (FENCHEN >= '100') THEN
'6'
ELSE
NULL
END)
FROM NODE_LATEST
INNER JOIN NODE_TREEVIEW
ON NODE_LATEST.LL_ADDR = NODE_TREEVIEW.LL_ADDR
从上面的sql中可以明显看出,把不满足条件的数据显示为null
更多追问追答
追问
但是null这个会显示出来的吧?
追答
是啊,可以用''代替null,这样就显示空白了
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询