给用户设一个积分,根据积分来查询用户的等级例如:用户表中的用户积分分别为15,25,等级表中,10-20为初级,20-30为中级,已知用户积分,如何显示等级?

解决方案 »

  1.   

    select 用户名,
           等级=case when score between 10 and 19 then '初级' when score between 20 and  30 then '中级' end
    from 表
      

  2.   

    declare @t table([name] varchar(10),jifen int)
    insert into @t select 'song',10
    insert into @t select 'yhtt',11
    insert into @t select 'yhy',23
    insert into @t select 'yrrr',30
    insert into @t select 'ntr',8
    insert into @t select 'j',6
    select [name],case when jifen>=10 and jifen<20 then '低级'
                       when jifen>=20 and jifen<30 then '中级' 
                  end as 等级
    from @t
      

  3.   

    declare @t table([name] varchar(10),jifen int)
    insert into @t select 'song',10
    insert into @t select 'yhtt',11
    insert into @t select 'yhy',23
    insert into @t select 'yrrr',30select [name],case when jifen>=10 and jifen<=20 then '低级'
                       when jifen>21 and jifen<=30 then '中级' 
                  end as 等级
    from @t
      

  4.   

    SELECT
            NAME,
           (
             CASE 
                   WHEN USER_SCORE BETWEEN 10 AND 19 THEN '初级' 
                   WHEN USER_SCORE BETWEEN 20 AND 30 THEN '中级'
             END
           ) AS 等级
    FROM
          TABLE 
    WHERE 1 = 1
      

  5.   

    select _name
    from  
    where _need=(
    select max(_need)
    from 
    where (select u_point from users where u_id=?)>=_need这是我自己写的,好象太麻烦了
    其中_name是等级名称,_need是达到这个等级所需的分数.u_point是用户现在的分数
    大家好象都是用between写的,如果等级有很多的话,我不可能把每一个档次都列出来啊,那句子也太长了!
    也许是我没说清楚吧,呵呵!
    谁能帮我精简一下我这个句子啊,我这个方法没什么效率可言的
      

  6.   

    select 用户,等级=(case 积分 when between 10 and 20 then '初级' when between  20 and 30 then '中级' end)
    from #t
      

  7.   

    再加20分,谁有更好的方法
    aniude(重返荣耀) 你用的还是between啊