① sql分组统计求百分比
SELECT
区
,CONVERT(DECIMAL(15,3),SUM(CASE 及格WHEN 'Y' THEN 1 ELSE 0 END))/COUNT(1)*100
FROM
表
GROUP BY
区
-------------输出结果-------------
A 100.00000000000000
B 33.33333333333300
C 50.00000000000000
② SQL SEVER如何分类汇总后再求每一项所占的百分比
SELECT国家,sum(出口量)as出口数量,SUM(出口量)*100.0/(selectSUM(出口量)fromseamlesswhere年份=2015)as占比
FROMseamlesswhere年份=2015
groupby国家
orderby出口数量desc
③ SQLSERVER数据库求每列不同数据所占百分比
如果只有abc这三种数据的话,就应该这样做:
先求出a的个数:select count(*) from table where name='a',
再求出总数据的个数:select count(*) from table
你可以先定义一个变量,那么a所占的比例就是:
declare @avg float
set @avg =select count(*) from table where name='a'/select count(*) from table
后面的依次类推。。。。
如果不止这三种数据的话,你可以先用group by先分一下组,然后再求比例。
④ 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语句,查询某个值在数据集中的占比情况
写一个sql语句恐怕不行。
应当先写一段sql语句,计算出links字段的总和。
然后再写一段sql语句,以links字段的每一个值除以links字段的总和,这样就能得出links字段每个值在该字段总和里的占比。
这种情况下,就要写两端sql语句。
⑥ sql 怎么求比例
declare @sumNum decimal(9,2)
set @sumNum=select sum([销售额]) from [产品销售表]
select [产品],sum([销售额]) as [销售额] ,sum([销售额])/@sumNum as [占比] from [产品销售表]
group by [产品]
⑦ sql 求占比
select
t1.province,
cast(count(1)*100/(selectcount(1)fromprovince)asvarchar(10))+'%'
from
provincet1
groupby
t1.province
⑧ 求SQL语句,按照不同条件分类统计想求一条sql 语句,统计某个字段数值之和,以及所占百分比,比如
SELECT 列1, 列2, COUNT(*)FROM T1GROUP BY 列1, 列2SELECT 列1, 列2, 列3, COUNT(*)FROM T1GROUP BY 列1, 列2, 列3 delphi我不懂,但是具体的语言和数据库是无关的。
⑨ 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