if object_id('tb') is not null
drop table tb
gocreate table tb(id int,bamt int,checkout int)
insert into tb select 1,100,1111
insert into tb select 2,325,2222
insert into tb select 3,525,1111
insert into tb select 2,100,3333select id,case when count(1)>1 then 'max' else 'min' end as '结果' from tb
group by idid 结果
1 min
2 max
3 min
drop table tb
gocreate table tb(id int,bamt int,checkout int)
insert into tb select 1,100,1111
insert into tb select 2,325,2222
insert into tb select 3,525,1111
insert into tb select 2,100,3333select id,case when count(1)>1 then 'max' else 'min' end as '结果' from tb
group by idid 结果
1 min
2 max
3 min
drop table tb
gocreate table tb(id int,bamt int,checkout int)
insert into tb select 1,100,1111
insert into tb select 2,325,2222
insert into tb select 3,525,1111
insert into tb select 2,100,3333select id,case when count(1)>1 then 'max' else ltrim(count(id)) end as '结果' from tb
group by idid 结果
1 1
2 max
3 1count(1)和count(id)效果一样
select chec=case when count(id)>1 then 'Min' else '' end from bamt
的from 最少要有End
的from前最少要有End