------解决方案-------------------- WITH TEST AS (
SELECT '44' AS N_CART_ID,'6999' AS N_PRICEN_AMOUNT FROM DUAL
UNION ALL
SELECT '61' AS N_CART_ID,'4500' AS N_PRICEN_AMOUNT FROM DUAL
UNION ALL
SELECT '62' AS N_CART_ID,'24600' AS N_PRICEN_AMOUNT FROM DUAL
UNION ALL
SELECT '63' AS N_CART_ID,'14498' AS N_PRICEN_AMOUNT FROM DUAL
UNION ALL
SELECT '65' AS N_CART_ID,'26400' AS N_PRICEN_AMOUNT FROM DUAL
UNION ALL
SELECT '81' AS N_CART_ID,'796' AS N_PRICEN_AMOUNT FROM DUAL
)
select N_CART_ID,SUM(N_PRICEN_AMOUNT)OVER() AS N_PRICEN_AMOUNT FROM TEST
这个效果? ------解决方案--------------------
感觉不是很清楚你要什么,你看看我写的这个吧
SELECT DECODE(GROUPING(n_cart_id), 1, 'All value',
n_cart_id) AS n_cart_id,
SUM(n_price*n_amount)
FROM info_shopping_cart_tab
GROUP BY ROLLUP (n_cart_id);
------解决方案-------------------- 再套一层
SELECT SUM(AMOUNT) FROM
(SELECT N_CART_ID,SUM(N_PRICE*N_AMOUNT) AMOUNT FROM INFO_SHOPPING_CART_TAB group by N_CART_ID) ------解决方案-------------------- 你想在分组后再SUM的话就再加一层SUM吧。 ------解决方案--------------------
SELECT a.n_cart_id,a.gross,b.gross FROM
(SELECT n_cart_id,SUM(n_price*n_amount) gross
FROM info_shopping_cart_tab
GROUP BY n_cart_id) a,
(SELECT SUM(n_price*n_amount) gross
FROM info_shopping_cart_tab) b
这个行伐?
------解决方案-------------------- select d.id,sum(d.num1*d.num2) from test1 d group by d.id
union all
select '求和' , sum(d.num1*d.num2) from test1 d; ------解决方案-------------------- 按照你的需求只有这样了:
SELECT N_CART_ID,N_PRICE,N_AMOUNT,SUM(N_PRICE*N_AMOUNT) AMOUNT FROM INFO_SHOPPING_CART_TAB group by N_CART_ID,N_PRICE,N_AMOUNT