Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/59.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 将where条件转换为case when_Mysql_Sql - Fatal编程技术网

Mysql 将where条件转换为case when

Mysql 将where条件转换为case when,mysql,sql,Mysql,Sql,我想创建两个参数在同一列中的数据,但我不知道如何将它们与每个条件分开 case when a.ps='p' then a.ccyamt else '' as base_ccy_amount_buy case when a.ps='p' then a.spotrate_8 else '' as rate_buy case when a.ps='s' then a.ctramt else '' as base_ccy_amount_sell case when a.ps='s' then a.spo

我想创建两个参数在同一列中的数据,但我不知道如何将它们与每个条件分开

case when a.ps='p' then a.ccyamt else '' as base_ccy_amount_buy
case when a.ps='p' then a.spotrate_8 else '' as rate_buy
case when a.ps='s' then a.ctramt else '' as base_ccy_amount_sell
case when a.ps='s' then a.spotrate_8 else '' as rate_sell
from fxdh a
这样使用我的代码可以吗

然后我想计算一下

 (E.SPOTRATE_8 * A.CTRAMT) + (E.SPOTRATE_8 * A.CCYAMT  * -1)
我想从a.ps=s到e.spotrate\u 8*a.ctramt,从a.ps=p到e.spotrate\u 8&a.ccyamt,这样使用我的代码可以吗?总的来说,是的。然后我想计算,就像您可以使用前面的查询作为CTE/子查询一样,并进行适当的聚合。但是我建议将您以前的查询划分为两个查询(每个查询都有自己的
a.ps
value),并通过其他列将它们连接起来。