gpt4 book ai didi

php - 在 mysql 中使用条件选择 SUM()

转载 作者:太空宇宙 更新时间:2023-11-03 11:01:29 25 4
gpt4 key购买 nike

假设我有

SELECT `Type`, `Originating Country Code`,`Originating Currency Code`, SUM(`Principal Amount`) as Total 
FROM `colab`
WHERE (`Destination Country Code`='PH'
AND `Destination Currency Code`='PHP'
AND `Type` = 'PAID') || (`Destination Country Code`='PH'
AND `Destination Currency Code`='USD'
AND `Type`= 'PAID')
GROUP BY `Type`

工作正常并返回 true 请看下面

country_code | Currency_Code  |   Type    |  Principal

=======================================================
| PH | PHP | PAID | 200
=======================================================

我的问题是我想将货币的本金总额与美元值(value)分开。请查看我数据库中的记录

country_code | Currency_Code  |   Type    |  Principal

=======================================================
| PH | PHP | PAID | 100
| PH | USD | PAID | 100
=======================================================

最佳答案

试试这个查询:

SELECT `Currency_Code`, SUM(`Principal Amount`) as Total 
FROM `table`
GROUP BY `Currency_Code`

关于php - 在 mysql 中使用条件选择 SUM(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15318481/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com