|
发表于 2020-5-27 09:15:01
|
显示全部楼层
create table ta(日期 varchar(5), 型号 varchar(2), 销售量 int)
insert ta
select '12.1', 'A', 2
union all select '12.1', 'B', 1
union all select '12.1', 'C', 1
union all select '12.1', 'E', 3
union all select '12.1', 'F', 1
union all select '12.1', 'H', 2
union all select '12.1', 'I', 1
union all select '12.2', 'A', 1
union all select '12.2', 'C', 1
union all select '12.2', 'D', 1
union all select '12.2', 'E', 4
union all select '12.2', 'H', 2
select 型号,销售号=sum(销售量),销售号=sum(销售量),
百分比=str(convert(numeric(5,2),sum(销售量))/(select sum(销售量) from ta),5,2)--转换整数
from ta group by 型号
having str(convert(numeric(5,2),sum(销售量))/(select sum(销售量) from ta),5,2)=.35--定义表达式等于35%就行了
order by 销售号 desc
型号 销售号 销售号 百分比
---- ----------- ----------- -----
E 7 7 0.35
(所影响的行数为 1 行)
|
|