首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何增加根据一组条件变化的折扣栏?

如何增加根据一组条件变化的折扣栏?
EN

Stack Overflow用户
提问于 2019-06-24 19:38:36
回答 2查看 120关注 0票数 0

我想添加折扣列,它根据帐户类型和服务的不同而不同。任何表中都不存在折扣列。

我希望在运行时有一个列折扣列,而折扣根据Resller_nameAccount_type和服务的不同而不同。

如何添加折扣栏?

此外,我需要添加计算成本列与以下公式: a.list_cost*(1-d.discount)。我尝试创建了一个表折扣,并添加了异常值,并创建了以下脚本:

代码语言:javascript
复制
select a.account, a.name, b.Resller_Name, b.bcn, 
b.Account_Type as "Internal\reseller", a.service, a.list_cost "cost of service",
d.discount, a.list_cost*(1-d.discount) as "Calculated Cost" 
from imtest.cloudchckr_test_full a, imtest.master_info_test_full b, imtest.discount d 
where a.account=b.AWS_id(+) and b.Account_type=d.account_type; 

但它只在帐户类型的基础上显示折扣。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-06-24 19:45:38

您可以在折扣表中添加order is或在折扣表中添加任何唯一的Id,然后连接所有表并获取折扣金额。与折扣表进行左连接,如果数据不存在,则会得到空值。

票数 0
EN

Stack Overflow用户

发布于 2019-06-24 19:56:58

代码语言:javascript
复制
select 
   a.account, 
   a.name, 
   b.Resller_Name, 
   b.bcn, 
   b.Account_Type as "Internal\reseller", 
   a.service, 
   a.list_cost "cost of service", 
   d.discount, 
   a.list_cost*(1-d.discount) as "Calculated Cost" 
from imtest.cloudchckr_test_full a, 
   imtest.master_info_test_full b, 
   imtest.discount d 
where 
   a.account=b.AWS_id(+) 
   and (d.account_type is null or b.Account_type=d.account_type)
   and (d.Resller_Name is null or b.Resller_Name=d.Resller_Name)
   and (d.service is null or a.service=d.service)
UNION ALL
select 
   a.account, 
   a.name, 
   b.Resller_Name, 
   b.bcn, 
   b.Account_Type as "Internal\reseller", 
   a.service, 
   a.list_cost "cost of service", 
   0, 
   a.list_cost as "Calculated Cost" 
from imtest.cloudchckr_test_full a, 
   imtest.master_info_test_full b
where 
   a.account=b.AWS_id(+) 
   and not exists 
        (SELECT 1 
             FROM imtest.discount d 
          WHERE (d.account_type is null or b.Account_type=d.account_type)
            and (d.Resller_Name is null or b.Resller_Name=d.Resller_Name)
            and (d.service is null or a.service=d.service)
         )
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56735747

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档