本帖最后由 huaxinlinux 于 2023-10-18 17:49 编辑
请教各位大佬,我有两条查询语句想糅合到一起,试了好久都不行。看哪位大佬有兴趣给瞅瞅。
[SQL] 纯文本查看 复制代码 SELECT
ROUND(SUM(CASE
WHEN XF_TXDATE BETWEEN TRUNC(SYSDATE) AND TRUNC(SYSDATE) THEN XF_AMTSOLD
ELSE 0
END) / 10000, 10) AS today_total_sales,
ROUND(SUM(CASE
WHEN XF_TXDATE BETWEEN TRUNC(SYSDATE) AND TRUNC(SYSDATE) THEN (XF_AMTSOLD-XF_MALLBEARCOUPONAMOUNT-XF_STOREBEARCOUPONAMOUNT)
ELSE 0
END) / 10000, 10) AS today_net_sales,
ROUND(SUM(CASE
WHEN XF_TXDATE BETWEEN TRUNC(SYSDATE, 'MM') AND TRUNC(SYSDATE) THEN XF_AMTSOLD
ELSE 0
END) / 10000, 10) AS month_total_sales,
ROUND(SUM(CASE
WHEN XF_TXDATE BETWEEN TRUNC(SYSDATE, 'MM') AND TRUNC(SYSDATE) THEN (XF_AMTSOLD-XF_MALLBEARCOUPONAMOUNT-XF_STOREBEARCOUPONAMOUNT)
ELSE 0
END) / 10000, 10) AS month_net_sales,
ROUND(SUM(CASE
WHEN XF_TXDATE BETWEEN TO_DATE('2023-05-01', 'YYYY-MM-DD') AND TRUNC(SYSDATE) THEN XF_AMTSOLD
ELSE 0
END) / 10000, 10) AS year_total_sales,
ROUND(SUM(CASE
WHEN XF_TXDATE BETWEEN TO_DATE('2023-05-01', 'YYYY-MM-DD') AND TRUNC(SYSDATE) THEN (XF_AMTSOLD-XF_MALLBEARCOUPONAMOUNT-XF_STOREBEARCOUPONAMOUNT)
ELSE 0
END)/ 10000, 10) AS year_net_sales
FROM
xf_transsalesitem t, xf_mdcontracth m
WHERE
t.xf_storecode = m.xf_contractno
AND XF_CASHMODE=1
GROUP BY XF_BUSINESSTYPE;
这一段的XF_CASHMODE=1 XF_BUSINESSTYPE in(4,5)
[SQL] 纯文本查看 复制代码 select * from
(select round(sum(XF_AMTSOLD)/10000,10) a,
round((sum(XF_AMTSOLD)
-sum(XF_MALLBEARCOUPONAMOUNT)
-sum(XF_STOREBEARCOUPONAMOUNT))/10000,10) b
from xf_transsalesitem t , xf_mdcontracth m
where XF_TXDATE >=trunc(sysdate-1)
and XF_TXDATE<=trunc(sysdate-1)
and t.xf_storecode=m.xf_contractno
and XF_BUSINESSTYPE=4
and XF_CASHMODE=0),
(select round(sum(XF_AMTSOLD)/10000,10) c,
round((sum(XF_AMTSOLD)
-sum(XF_MALLBEARCOUPONAMOUNT)
-sum(XF_STOREBEARCOUPONAMOUNT))/10000,10) d
from xf_transsalesitem t , xf_mdcontracth m
where XF_TXDATE >=trunc(sysdate,'month')
and XF_TXDATE<=trunc(sysdate-1)
and t.xf_storecode=m.xf_contractno
and XF_BUSINESSTYPE=4
and XF_CASHMODE=0),
(select round(sum(XF_AMTSOLD)/10000,10) e,
round((sum(XF_AMTSOLD)
-sum(XF_MALLBEARCOUPONAMOUNT)
-sum(XF_STOREBEARCOUPONAMOUNT))/10000,10) f
from xf_transsalesitem t , xf_mdcontracth m
where XF_TXDATE >=to_date('20230501','yyyymmdd')
and XF_TXDATE<=trunc(sysdate-1)
and t.xf_storecode=m.xf_contractno
and XF_BUSINESSTYPE=4
and XF_CASHMODE=0)
这一段的XF_CASHMODE=0 XF_BUSINESSTYPE =4
是求不同时间段的sum,想通过一条语句查出来,或者有什么更好的写法。 |