select case when (SELECT count(*) FROM cdb_posts where authorid=c.uid)>=10 then 10 when (SELECT count(*) FROM cdb_posts where authorid=c.uid)<5 then -10 else -5 end as post from cdb_members c wheregroupid='3'这个语句(SELECT count(*) FROM cdb_posts where authorid=c.uid)能简写不????

解决方案 »

  1.   

    select case when aa>=10 then 10 
    when aa<5 then -10 else -5 end
    from (
    SELECT count(*) as aa FROM cdb_posts a 
    inner join cdb_members c 
    on a.authorid=c.uid
    where c.groupid='3') a
      

  2.   

    or
    select if(aa>=10,10,if(aa<5,-10,-5)) 
    from ( 
    SELECT count(*) as aa FROM cdb_posts a 
    inner join cdb_members c 
    on a.authorid=c.uid 
    where c.groupid='3') a1
      

  3.   

    没什么特别简化的,select case when count(*) >=10 then 10 when count(*) >=5 then -5  else -10 end as post
    from cdb_members c inner join cdb_posts p on c.uid=p.authorid
    where c.groupid='3'