我试图减去卖出的美元兑买入的美元.
**|Tran_ID|Currency_type|currency_Amount|Local_Amount| Rate |Tran_type| **
| 85 | USD | 2500 | 1581.54 |1.58074 | Bought |
| 78 | USD | 3487.57 | 2206.29 |1.58074 | Bought |
| 86 | USD | 100 | 63.26 |1.58074 | Bought |
| 87 | USD | 94.17 | 63.26 |1.48866 | Sold |
| 88 | USD | 2600 | 1746.54 |1.48866 | Sold |
| 89 | USD | 2600 | 1746.54 |1.48866 | Sold |
我可以使用下面的查询添加已售出或已购买的美元总价值
SELECT Currency_type, sum( currency_Amount ) AS total_bought
FROM Transaction
WHERE Currency_type= 'USD'
AND Tran_type = 'Bought' <== **or 'Sold'**
**|Currency_type | total_bought |**
|USD |6087.570068359375|
解决方法:
您只需在交易类型上设置标志:
SUM(currency_Amount * IF(Tran_type = "Bought", 1, -1))
标签:sql,mysql
来源: https://codeday.me/bug/20190725/1534801.html
mysql
_
一列
分多行操作,在一个表里的几行数据需要分拆成单行存储到一
行中
,
mysql
_
一列
分多行操作,在一个表里的几行数据需要分拆成单行存储到一
行中
mysql
_
一列
分多行操作,在一个表里的几行数据需要分拆成单行存储到一
行中
mysql
_
一列
分多行操作,在一个表里的几行数据需要分拆成单行存储到一
行中
让我们首先创建一个表-createtableDemoTable741(Numberint);使用插入命令在表
中
插入一些记录-insertintoDemoTable741values(70);insertintoDemoTable741values(55);insertintoDemoTable741values(89);insertintoDemoTable741v...
SELECT isnull(A,0)-isnull(B,0) AS 结果 FROM 表 --sqlserver语法
SELECT nvl(A,0)-nvl(B,0) AS 结果 FROM 表 --Oracle语法
SELECT ifnull(A,0)-ifnull(B,0) AS 结果 FROM 表 --
mysql
语法
(select
(SELECT settlement_amount FROM `domestic_vendor_statements`
where billing_month='202203') a,
(SELECT settlement_amount FROM `domestic_vendor_statements`
where billing_month='202204') b) as
表结构? 测试数据?按哪
一列
排序?测试数据.CREATE TABLE temp (year INT,salary INT);INSERT INTO temp VALUES(2000, 1000);INSERT INTO temp VALUES(2001, 2000);INSERT INTO temp VALUES(2002, 3000);INSERT INTO temp VALUES(...
I want to display the subtraction of two values from two different columns to a third column using a SQL query.This is the table structure:------------------------------------id | subject | Time1 | Ti...