我有 2 个这样的 SQL 查询
SELECT TOP 100 PERCENT
COUNT(kodeall) AS Total, kodeall, kode, LEFT(kodeall, 1) AS kode1
FROM
dbo.data
WHERE
date BETWEEN '2013/03/01 00:00:00' AND '2013/03/01 23:59:00'
AND (kodeall IS NOT NULL)
GROUP BY
kodeall, kode
ORDER BY
kode1
和结果
Total l kodeall l kode l kode1
2 1a AA 1
5 1d BB 1
2 2a CC 2
6 2d DD 2
1 2e EE 2
3 3a FF 3
2 3c GG 3
1 3f WW 3
查询 #2:
SELECT
COUNT(kodeall) AS Sum, LEFT(kodeall, 1) AS kode1
From
dbo.data
WHERE
date BETWEEN '2013/03/01 00:00:00'
AND '2013/03/01 23:59:00'
AND (kodeall IS NOT NULL)
GROUP BY
LEFT(kodeall, 1)
和结果
Sum l kode1 l
7 1
9 2
6 3
如果我想显示这样的结果
Total l kodeall l kode l kode1 l sum l Percentage
2 1a AA 1 7 28.57 %
5 1d BB 1 7 71.43 %
2 2a CC 2 9 22.22 %
6 2d DD 2 9 66.66 %
1 2e EE 2 9 11.11 %
3 3a FF 3 6 50 %
2 3c GG 3 6 33.33 %
1 3f WW 3 6 16.67 %
sum 是查询 A 中 kode1 的 count kodeall。
和百分比 = 总计 / 总和 *100 示例 2/7*100
请帮我