【问题标题】:Adding Columns in SQL在 SQL 中添加列
【发布时间】:2014-12-03 08:33:20
【问题描述】:

我在选择查询中有这个等式

监控费用"+"CCN 费用"+"WkRpt 费用"+"MonRpt 费用"+"客户仪表板费用"+"Take
控制服务器费用”+“补丁管理服务器费用”+“远程后台服务器费用”
作为“总上限服务器费用”

我看到的一个问题是,它只会在每列中有值的情况下添加,但即使没有数据,我也需要添加它。

对于远程后台服务器,费用要到 2013 年 9 月才会开始计算。因此,在所有内容都有值之前,总上限服务器费用等式不会将其他费用相加,因此它从 2013 年 9 月开始,而不是所有年份。

【问题讨论】:

  • 将“远程后台服务器费用”列添加为空值。

标签: sql select arithmetic-expressions


【解决方案1】:

一些列返回NULL。您需要使用ISNULL 来返回0 而不是NULL。例如:

ISNULL("Monitoring Fees", 0) + 
ISNULL("CCN Fees", 0) + 
ISNULL("WkRpt Fees", 0) + 
ISNULL("MonRpt Fees", 0) + 
ISNULL("Client Dashboard Fees", 0) + 
ISNULL("Take Control Servers Fees", 0) + 
ISNULL("Patch Management Servers Fees", 0) + 
ISNULL("Remote Background Servers Fees", 0) as "Total Capped Server Fees"

我假设您使用的是 SQL Server。

如果您使用的是 MySQL,则等效函数为 IFNULL。例如:

IFNULL("Monitoring Fees", 0) + 
IFNULL("CCN Fees", 0) + 
IFNULL("WkRpt Fees", 0) + 
IFNULL("MonRpt Fees", 0) + 
IFNULL("Client Dashboard Fees", 0) + 
IFNULL("Take Control Servers Fees", 0) + 
IFNULL("Patch Management Servers Fees", 0) + 
IFNULL("Remote Background Servers Fees", 0) as "Total Capped Server Fees"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多