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

解决方案 »

  1.   

    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 ltrim(count(id)) end as '结果' from tb
    group by idid 结果
    1 1
    2 max
    3 1count(1)和count(id)效果一样
      

  2.   

    尽可能不用count(字段名),用count(*)或count(number).
      

  3.   

    select chec=case when count(id)>1 then 'Min' from bamt -->
    select chec=case when count(id)>1 then 'Min' else '' end from bamt
      

  4.   

    select chec=case when count(id)>1 then 'Min' from bamt 
    的from 最少要有End
      

  5.   

    select chec=case when count(id)>1 then 'Min' from bamt 
    的from前最少要有End