① sql SEVER如何分類匯總後再求每一項所佔的百分比
SELECT國家,sum(出口量)as出口數量,SUM(出口量)*100.0/(selectSUM(出口量)fromseamlesswhere年份=2015)as佔比
FROMseamlesswhere年份=2015
groupby國家
orderby出口數量desc
② sql 怎麼用一個語句求出同一列的某一個欄位在整個列的百分比
可考慮使用窗口函數,計算各行某欄位數值占整列的百分比:
selectratio_to_report(sal)over()fromemp;
網路你妹,我不修改了,最好把我回答刪掉。
以上。
③ sql sever 如何算條件聚類後各自占的百分比
selecttable1.tas水果,table1.shuas'pz=1的數量',table2.shuas總數量,cast(table1.shu*100/table2.shuasvarchar)+'%'as'pz=1佔比'from
(selecttypeast,COUNT(pz)asshufromtenwherepz=1groupbytype)astable1
leftjoin(selecttypeast,COUNT(*)asshufromtengroupbytype)astable2ontable1.t=table2.t
④ 求一個SQL百分佔比的寫法
你沒試嗎?這就是所有占總銷量80%的所有客戶,您糊塗了嗎?即然您只要了80%的客戶,都是一個百分數,還有什麼多少?還排什麼序?
不過,看在分的面子上,後面我又給了您占總銷量80%以上的所有客戶按銷量反排序的查詢。
MSSQL:
select
A,
SUM(B) AS 銷售額合計,
100*SUM(B)/(SELECT SUM(B) FROM 表) AS 占總百分比
FROM 表 group by A
HAVING 100*SUM(B)/(SELECT SUM(B) FROM 表)=80
select
A,
SUM(B) AS 銷售額合計,
100*SUM(B)/(SELECT SUM(B) FROM 表) AS 占總百分比
FROM 表 group by A
HAVING 100*SUM(B)/(SELECT SUM(B) FROM 表)=80
占總銷量80%以上的所有客戶按銷量排序。
select
A,
SUM(B) AS 銷售額合計,
100*SUM(B)/(SELECT SUM(B) FROM 表) AS 占總百分比
FROM 表 group by A
HAVING 100*SUM(B)/(SELECT SUM(B) FROM 表)>=80
order by SUM(B) desc
⑤ 用SQL查詢佔比
sqlserver寫法
創建表
create table test
(id int,
name varchar(1))
insert into test values (1,'a')
insert into test values (2,'a')
insert into test values (1,'a')
insert into test values (1,'a')
insert into test values (2,'a')
執行
select a.id,a.count1,(a.count1+0.0)/b.count2
from
(select id,count(*) count1 from test group by id) a,
(select count(*) count2 from test) b
⑥ 求sql語句查出一行數據中每列的百分比
1、若針對每行求百分比:
select SA/TotelTime ,SB/TotelTime ,SC/TotelTime ,SD/TotelTime ,SE/TotelTime from 表名
2、若是對總計後的值求百分比:
select sum(SA)/sum(TotelTime) ,sum(SB)/sum(TotelTime) ,sum(SC)/sum(TotelTime) ,sum(SD)/sum(TotelTime) ,sum(SE)/sum(TotelTime) from 表名
3、當然,以上都是以小數形式顯示結果,若要以百分比形式顯示結果:乘以100,並保留兩位小數,然後加上「%」即可。
如:round((SA/TotelTime)*100,2) & "%"
⑦ SQL 兩次分組求百分比
select order_type,is_olser,sum(counts)/c2 from order_today
lett join (select order_type ot,sum(counts) c2 from group by order_today) ot2 on ot2.ot=order_today.order_type
group by order_type,is_olser,c2
⑧ 使用sql語句計算百分比
1、若針對每行求百分比: select SA/TotelTime ,SB/TotelTime ,SC/TotelTime ,SD/TotelTime ,SE/TotelTime from 表名 。
2、若是對總計後的值求百分比: select sum(SA)/sum(TotelTime) ,sum(SB)/sum(TotelTime) ,sum(SC)/sum(TotelTime) ,sum(SD)/sum(TotelTime) ,sum(SE)/sum(TotelTime) from 表名
3、當然,以上都是以小數形式顯示結果,若要以百分比形式顯示結果:乘以100,並保留兩位小數,然後加上「%」即可。
如:round((SA/TotelTime)*100,2) & "%"
⑨ sql 求佔比
select
t1.province,
cast(count(1)*100/(selectcount(1)fromprovince)asvarchar(10))+'%'
from
provincet1
groupby
t1.province
⑩ 求一個sql語句,查詢某個值在數據集中的佔比情況
寫一個sql語句恐怕不行。
應當先寫一段sql語句,計算出links欄位的總和。
然後再寫一段sql語句,以links欄位的每一個值除以links欄位的總和,這樣就能得出links欄位每個值在該欄位總和里的佔比。
這種情況下,就要寫兩端sql語句。