create table ordertest(type varchar(3), num int)
insert into ordertest
select 'AAA', 1
union all select 'AAA', 3
union all select 'AAA', 5
union all select 'AAA', 7
union all select 'BBB', 1
union all select 'BBB', 3
union all select 'BBB', 5
union all select 'BBB', 7
union all select 'CCC', 1
union all select 'CCC', 3
union all select 'CCC', 5
union all select 'BBB' ,9
select type, sum(num) as num from ordertest
where num 0
group by type
having sum(num) 8
select type, sum(num) as num from ordertest
where num 2
group by type
having sum(num) 8
select type, sum(num) as num from ordertest
where num 2
group by type
having sum(num) 8
order by num desc