如果值大于其他列名,则如何显示列名 [英] How to show a column name if value is greater else the other column name

查看:72
本文介绍了如果值大于其他列名,则如何显示列名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

select SoftwareName as Software,LicenseQty, AssignedQty,case when LicenseQty>AssignedQty then (LicenseQty-AssignedQty) else 0 end as FreeQty,case when AssignedQty>LicenseQty
then (AssignedQty-LicenseQty)else 0 end as ExcessQty from TblSoftware

推荐答案

select SoftwareName as Software,LicenseQty, AssignedQty,
case when LicenseQty>AssignedQty then (LicenseQty-AssignedQty) else 0 end as FreeQty,
case when AssignedQty>LicenseQty
then (AssignedQty-LicenseQty)else 0 end as ExcessQty,
-- to get column name who have greater value do the following
case when AssignedQty>LicenseQty then  "AssignedQty" else "LicenseQty" end as ColumnWithGreaterValue
from TblSoftware;


这篇关于如果值大于其他列名,则如何显示列名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆