可以傻傻的写
select name,(select score from t_test where name=o.name and lesson='语文') 语文,(select score from t_test where name=o.name and lesson='数学') 数学 from t_test o group by name

解决方案 »

  1.   

    谢谢先。可是lesson是动态的从数据库中读取的啊?我该如何实现呢??
      

  2.   

    那个SQL 你可以动态构造出来,再提交查询。
      

  3.   

    去SQL 区搜索 行变列 肯定有高手有更佳的解决方法。所以我的才是 [傻傻的]
      

  4.   

    这个就可以,挺好的!
    http://topic.csdn.net/u/20080107/19/82918308-43be-4c39-8654-4cd8c0a0ac38.html
      

  5.   

    select name ,(case lesson when '语文' then score else '' end) as 语文,
                 (case lesson when '数学' then score else '' end) as 数学,
                 (case lesson when '英语' then score else '' end) as 英语
    from table
    order by id
    试试这样,我没有调试,不知道行不行,有问题再提吧