我想将小数位改为4,但无法弄明白,帮助!
- 查询
select CASE v2.[ie version]
When '11' Then 'Internet Explorer 11'
When '9' Then 'Internet Explorer 9'
When '8' Then 'Internet Explorer 8'
Else [IE Version] End [IE Version],
COUNT(distinct v1.guid) 'Total Count', COUNT(*) *100.00 / SUM(COUNT(*)) over()'Total Percentage' from vcomputer v1
inner join vIEVersions v2 on v1.guid = v2.guid where v1.ismanaged = '1'
and v2.[IE Version] is not Null and v2.[IE Version] not in ('Unknown', '7', '10')
group by v2.[IE Version] order by 1 desc
- 输出
IE Version Total Count Total Percentage
Internet Explorer 9 180 1.7349397590361
Internet Explorer 8 531 5.1180722891566
Internet Explorer 11 9664 93.1469879518072
答案 0 :(得分:0)
我认为首先你必须先得到CREATE TABLE VIEW
小数百分比细分,然后调用round函数得到总和的值,如下例所示:
SELECT ROUND(column_name,decimals) FROM table_name;
希望它有所帮助。
答案 1 :(得分:0)
CAST到十进制应该足够了:
CAST(COUNT(*) *100.00 / SUM(COUNT(*)) over() as decimal(12,4))
答案 2 :(得分:0)
试试这个例子,
宣布@i int = 23
选择演员表(@ i * 100.00 / 3为十进制(10,4))