WITH test (name , quantity)
AS
(SELECT 'a', 1
UNION ALL
SELECT 'b', 2
UNION ALL
SELECT 'c', 7)
SELECT NAME,quantity,CONVERT(VARCHAR(10),CONVERT(FLOAT(5),quantity)/(select SUM(quantity)total FROM test)*100)+'%'
FROM test
/*
NAME quantity
---- ----------- -----------
a 1 10%
b 2 20%
c 7 70%
(3 行受影响)
*/
------其他解决方案-------------------- select name,quantity,cast(quantity/(select SUM(quantity) from A)*100 as varchar(10))+'%'
from A ------其他解决方案-------------------- 没用过,但是光这个问题,没必要group 哦 ------其他解决方案-------------------- Select T.Name,T.Qty,Cast(T.Qty/x.Qty*100 as varchar(10))+'%' as Perc
From _Tab T,(Select Sum(Qty) as Qty From _Tab) x