SQL语句问题

如何将SUM(FAMOUNT_BASE)与SUM(FDISCRATE) 的差值,写进下面的语句 ?

select SUM(FAMOUNT_BASE),SUM(FDISCRATE) FROM (

SELECT MA.FCODE,MA.FAMOUNT_BASE,DE.FDISCRATE

FROM BS_MV_SA_MA MA INNER JOIN BS_MV_SA_DE DE

ON MA.FMID=DE.FPID

WHERE TO_CHAR(MA.FBIZTIME,'YYYYMMDD')= TO_CHAR(sysdate,'YYYYMMDD')-1

AND MA.FSTATE=6

AND MA.FORG_STORE_CODE NOT LIKE 'S%'

UNION ALL

SELECT MA.FCODE,MA.FAMOUNT_BASE,DE.FDISCRATE

FROM BS_MV_SA_MA MA

INNER JOIN BS_MV_SA_DE DE

ON MA.FMID=DE.FPID

WHERE TO_CHAR(MA.FBIZTIME,'YYYYMMDD')= TO_CHAR(sysdate,'YYYYMMDD')-1

AND MA.FSTATE=6

AND  MA.FORG_STORE_DE_CODE NOT LIKE 'S%' )

FineReport rbk333 发布于 2023-3-30 18:02
1min目标场景问卷 立即参与
回答问题
悬赏:3 F币 + 添加悬赏
提示:增加悬赏、完善问题、追问等操作,可使您的问题被置顶,并向所有关注者发送通知
共1回答
最佳回答
0
runnerLv7资深互助
发布于2023-3-30 18:11

select SUM(FAMOUNT_BASE),SUM(FDISCRATE),

SUM(FAMOUNT_BASE)-SUM(FDISCRATE) as index1

 

 FROM (

SELECT MA.FCODE,MA.FAMOUNT_BASE,DE.FDISCRATE

FROM BS_MV_SA_MA MA INNER JOIN BS_MV_SA_DE DE

ON MA.FMID=DE.FPID

WHERE TO_CHAR(MA.FBIZTIME,'YYYYMMDD')= TO_CHAR(sysdate,'YYYYMMDD')-1

AND MA.FSTATE=6

AND MA.FORG_STORE_CODE NOT LIKE 'S%'

UNION ALL

SELECT MA.FCODE,MA.FAMOUNT_BASE,DE.FDISCRATE

FROM BS_MV_SA_MA MA

INNER JOIN BS_MV_SA_DE DE

ON MA.FMID=DE.FPID

WHERE TO_CHAR(MA.FBIZTIME,'YYYYMMDD')= TO_CHAR(sysdate,'YYYYMMDD')-1

AND MA.FSTATE=6

AND  MA.FORG_STORE_DE_CODE NOT LIKE 'S%' ) a

  • 2关注人数
  • 154浏览人数
  • 最后回答于:2023-3-30 18:11
    请选择关闭问题的原因
    确定 取消
    返回顶部