SQL多表查詢結果求百分比

2021-04-19 19:37:15 字數 300 閱讀 3428

select  部門=department, 部門資產數=count(hostsn),總資產數= (select count(sid) from dbo.computerinfo)

,百分比=cast(cast(count(hostsn)*1.0*100/(select count(sid) from dbo.computerinfo) as decimal(10,2)) as varchar(50)) +'%'

from dbo.hostinfo          where department <>'' group by department

sql語句求百分比

此sql語句包括了兩個聚合函式做除法求百分比,並保留兩位小數,直接輸出字串形式的百分比。以及對case when在聚合函式的應用。select ss.ss name,ss id,count ea.ea id as eacounts,回單交換單個數 count eb.eb id as ebcounts...

SQL求總和的百分比

先通過group by得到每個分類別的總和,再通過開窗函式計算整體的總和,兩者相除就得到佔比了。當over 後不加任何內容時,就是對所有的資料進行彙總。在oracle中,也可以使用專門的比例函式 ratio to report 來直接計算 上述操作可以更改如下 select sites id,cha...

oracle 求百分比

oracle求百分比 例子 求name為dead的記錄所佔百分比 select tt.retrieve retrievedrate,tc.公司名稱 companyname,tc.部門名稱 deptname,tc.使用者名稱 username,tc.nodename nodename,tc.proce...