有表 student
字段 id name age logo
我想查找 logo=0 和name!=''的让他在上边按ID分组
然后 logo=1 和name=''的在下边按ID分组
怎么写

解决方案 »

  1.   

    case when (logo=0 and name!='')or (logo=1 and name='') then ID else ... end
      

  2.   

    SELECT 
       * 
    FROM 
       ASso_member 
    WHERE 
       [logo] in ('0','1')                   and 
       picname is not null                
    ORDER BY
       [logo],case when picname ='' then 1 else 0 end
      

  3.   


    select '第一类'
    union all
    select id from  where logo=0 and name!='' group by id 
    union all 
    select '第二类'
    union all
    select id from  where logo=1 and name='' group by id 
      

  4.   

    select '第一类'
    union all
    select id from student where logo=0 and name!='' group by id 
    union all 
    select '第二类'
    union all
    select id from student where logo=1 and name='' group by id