我在oracle apex的数据库中有一个金额列,它有多个值,有些是<0和其他为>0。我想在报告中显示借方和贷方两列。如何使用SQL查询?请帮我写where子句。
select ANOID,
PERNOID,
PERNO,
AMOUNT as "Credit" , -- < 0
AMOUNT as "Debit", -- > 0
DESC_,
DEBIT,
ROW_ID
from DSVOUD
where
VOUID = :P11_VOUID
对这两列使用CASE语句:
select ANOID,
PERNOID,
PERNO,
case when AMOUNT < 0 then AMOUNT end as "Credit" ,
case when AMOUNT > 0 then AMOUNT end as "Debit",
DESC_,
DEBIT,
ROW_ID
from DSVOUD
where
VOUID = :P11_VOUID
这将在贷方金额的借方列中显示为空,反之亦然。您可能需要添加else 0
子句。