SELECT PRODUCT_NAME ,MONDAY ,TUESDAY ,WEDNESDAY ,THURSDAY ,FRIDAY ,(MONDAY+TUESDAY+WEDNESDAY +THURSDAY +FRIDAY+SATURDAY+SUNDAY) TT FROM(SELECT PRODUCT_name ,ROUND(SUM(CASE WHEN TO_CHAR(TRADE_DATE, 'day')='星期一' THEN AMOUNT ELSE 0 END),2) AS MONDAY ,ROUND(SUM(CASE WHEN TO_CHAR(TRADE_DATE, 'day')='星期二' THEN AMOUNT ELSE 0 END),2) AS TUESDAY ,ROUND(SUM(CASE WHEN TO_CHAR(TRADE_DATE, 'day')='星期三' THEN AMOUNT ELSE 0 END),2) AS WEDNESDAY ,ROUND(SUM(CASE WHEN TO_CHAR(TRADE_DATE, 'day')='星期四' THEN AMOUNT ELSE 0 END),2) AS THURSDAY ,ROUND(SUM(CASE WHEN TO_CHAR(TRADE_DATE, 'day')='星期五' THEN AMOUNT ELSE 0 END),2) AS FRIDAY ,ROUND(SUM(CASE WHEN TO_CHAR(TRADE_DATE, 'day')='星期六' THEN AMOUNT ELSE 0 END),2) AS SATURDAY ,ROUND(SUM(CASE WHEN TO_CHAR(TRADE_DATE, 'day')='星期日' THEN AMOUNT ELSE 0 END),2) AS SUNDAY ,ROUND(SUM(AMOUNT),2) AMOUNT FROM T05_FACT_TRADE T1 LEFT JOIN T02_DIM_PRODUCT T2 ON T1.PRODUCT_ID=T2.PRODUCT_ID WHERE TO_CHAR(TRADE_DATE, 'yyyy-mm-dd') >= '2022-05-04' AND TO_CHAR(TRADE_DATE, 'yyyy-mm-dd') < '2022-05-12' GROUP BY PRODUCT_name ) ORDER BY TT DESC标签:05,SUM,TRADE,CHAR,AMOUNT,险种,2022,DATE,ROUND From: https://www.cnblogs.com/duan-/p/16835937.html