我有這樣顯示結果的查詢
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
2個SQL查詢和結果
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 %
總和計kodeall通過在查詢A. kode1
和百分比=合計/總和* 100 例2/7 * 100
請幫我
歡迎StackOverflow上:如果您發佈的代碼,XML或數據樣本,** **請在高亮文本編輯器這些線路上,並點擊了的「代碼示例」按鈕('{}')編輯器工具欄以很好地格式化和語法突出顯示它!這樣,你不需要任何雜亂的'
'標籤! –
我是sory.thx您的信息。 – rian