test表
a      b     
222    11   
444    11   
456    22   
774    33   
910    33
...    ..   
查询结果:
222   444  11
456        12
774   910  33一条SQL能解决吗?

解决方案 »

  1.   

    select b,max(if(a=222,0)),max(if(a=444,a,0))....
    from tt group by b
      

  2.   

    假设A唯一
    select b,max(if(bz=1,a,0)), max(if(bz=2,a,0)) from (
    select a,b,(select count(*) from tt where a.b=b and a.a<=a) as bz
    from tt a) c
    group by b
      

  3.   

    select  min(a),max(a),b
    from test
    group by b
      

  4.   

    select group_concat(a SEPARATOR ' '),b
    from test表
    group by b