id  se  url
1 百度 sina.com
2 搜搜 sina.com
3 百度 163.com
4 搜搜 163.com
5 搜狗 sina.com
6 搜搜 189.com
7 搜狗 189.com
求结果
url       baidu soso sogua
sina.com  百度  搜搜  搜狗
163.com   百度  搜搜   --
189.com   --   搜搜   搜狗

解决方案 »

  1.   

    select url,max(if(se='百度',se,'')) as  baidu,
    max(if(se='搜搜',se,'')) as  soso,
    max(if(se='搜狗',se,'')) as  sogua
    from tt group by url
      

  2.   

    如果列数不确定的话  最好这样
    select url,group_conat(se)
    from tb
    group by url
      

  3.   


    group_conat mysql没这个函数吧
      

  4.   

    http://blog.csdn.net/acmain_chm/article/details/4283943
    MySQL交叉表
    在某些数据库中有交叉表,但在MySQL中却没有这个功能,但网上看到有不少朋友想找出一个解决方法,特发贴集思广义。http://topic.csdn.net/u/20090530/23/0b782674-4b0b-4cf5-bc1a-e8914aaee5ab.html?96198现整理解法如下:数据样本: create table tx(  id int primary key,  c1 c...