Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/56.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 如何执行一个查询来汇总3种类型的折扣?_Mysql - Fatal编程技术网

Mysql 如何执行一个查询来汇总3种类型的折扣?

Mysql 如何执行一个查询来汇总3种类型的折扣?,mysql,Mysql,我的tbl_发票中有以下字段 Invoice_Discount_Type | Invoice_Discount ---------------------------------------- null | null 84 | 750 84 | 1500 144 | 7 0 | 25 144

我的tbl_发票中有以下字段

Invoice_Discount_Type | Invoice_Discount
----------------------------------------
null                  | null
84                    | 750
84                    | 1500
144                   | 7
0                     | 25
144                   | 2
0                     | 16
---------------------------------------
在哪里

0代表百分比折扣。e、 g:25%

84代表黎巴嫩镑折扣。e、 g.750磅

144代表美元折扣。e、 g:7美元

我想做的是,执行一个查询,对特定日期(例如2015-12-27)的所有折扣求和,并以LBP(1美元=1500 LBP)返回结果

可能吗


谢谢你

看来你在找这样的东西

select sum(  
   case 
      when invoce_Discount_type = '84' then invoce_discount
      when invoce_Discount_type = '14' then invoce_discount  * 1500
   END
)  AS Discount 
from your_table;

看来你在找这样的东西

select sum(  
   case 
      when invoce_Discount_type = '84' then invoce_discount
      when invoce_Discount_type = '14' then invoce_discount  * 1500
   END
)  AS Discount 
from your_table;

对你可以用一个箱子来做statement@Strawberry我尝试了一个案例陈述,但没有成功您有两次84、144、0这是如何选择的,似乎您的架构不完整,请提供更多信息和更清晰的示例。@scaisEdge信息清晰。84、144和0是三种不同类型的折扣。表中有数千张发票,每张发票可能/可能没有折扣。在我的示例中,有7张发票,1张没有折扣,2张有LBP折扣,2张有美元折扣,2张有%折扣。我想做的是将所有非黎巴嫩折扣转换为LBP,汇总所有折扣,并显示一个结果。向我显示您希望获得的这七张发票的结果……是的。你可以用一个箱子来做statement@Strawberry我尝试了一个案例陈述,但没有成功您有两次84、144、0这是如何选择的,似乎您的架构不完整,请提供更多信息和更清晰的示例。@scaisEdge信息清晰。84、144和0是三种不同类型的折扣。表中有数千张发票,每张发票可能/可能没有折扣。在我的示例中,有7张发票,1张没有折扣,2张有LBP折扣,2张有美元折扣,2张有%折扣。我想做的是将所有非黎巴嫩折扣转换为LBP,汇总所有内容,并显示一个结果。显示您希望获得的这七张发票的结果。当我将其包含在sum函数中时,它起作用选择sum(情况I.Invoice\u折扣类型为84,然后I.Invoice\u折扣类型为144,然后(i.Invoice_折扣*1500)当0时,则(i.Invoice_Sub_Total-i.Invoice_Net_Total)结束)作为tbl_invoices i的折扣,其中i.Invoice_Date='2015-12-27'感谢您的时间@SCAISEDGET在我将其包含在SUM函数中时起作用选择SUM(案例i.发票折扣类型为84时,i.发票折扣类型为144时,i.发票折扣*1500)为0时,i.发票折扣总额-i.发票净额总额)结束)作为tbl发票i的折扣,其中i.发票日期='2015-12-27'感谢您的时间@scaisEdge