|
create table ta (date varchar (5), model varchar (2), sales volume 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 model, sales number = sum (sales volume), sales number = sum (sales volume),
Percentage = str (convert (numeric (5, 2), sum (sales)) / (select sum (sales) from ta), 5, 2)-convert integer
from ta group by model
having str (convert (numeric (5,2), sum (sales)) / (select sum (sales) from ta), 5,2) =. 35--define the expression equal to 35%
order by sales number desc
Model Sales Number Sales Number Percent
---- ----------- ----------- -----
E 7 7 0.35
(The number of rows affected is 1 row) |
|