22,210
社区成员
发帖
与我相关
我的任务
分享
declare @t table(id int,price decimal(4,2),name varchar(20))
insert into @t
select '1','20','一部'
union all select '2','25','一部'
union all select '3','10','二部'
union all select '4','5','三部'
--select [name],total=sum(price) from @t group by [name]
select t.[name],max(case when total>22 then total else null end) as total
from
(select [name],total=sum(price) from @t group by [name]) as t
group by t.[name]
order by t.[name] desc
select [name],total=sum(price) from tb group by [name]
declare @t table(id int,price decimal(4,2),name varchar(20))
insert into @t
select '1','20','一部'
union all select '2','25','一部'
union all select '3','10','二部'
union all select '4','5','三部'
select name,
case
when sum(isnull(price,0)) > 22 then sum(isnull(price,0))
else null
end
from @t
group by name
order by sum(isnull(price,0)) desc
select [name],total=sum(price) from tb group by [name]
select name,sum(price) total from tb group by name
select name ,sum(price) as 总计 from table group by name
SELECT name ,SUM(price)price FROM TB GROUP BY NAME