有一个表tb结构 如下字段 id name subject score
1 zhang math 90
1 biology 89
1 chemistry 69
2 wang math 23
2 biology 77
2 chemistry 100
3 li math 89
3 biology 78
3 chemistry 88id为学号,代表唯一一名学生
填充id相同的记录中空白的name
在sqlserver中实现语句为
select id,
name=(select top 1 name from tb where id=t.id order by name desc),
subject,score
from tb t
为什么在mysql下不行呢, 知道mysql不支持top,改为limit还是不行,求正确语句

解决方案 »

  1.   

    select id,(select name from tb where t.id =id group by id) as name, subject, score from tb t;试一下。
      

  2.   

    update 表tb a ,(select id,name from 表tb where name is not null group by id) b
    set a.name=b.name
    where a.id=b.id
    and a.name is null
      

  3.   

    select id,(select name from tb where t.id =id group by id) as name, subject, score from tb t;
      

  4.   

    update tb a, (select id,name from tb where name is not null group by id) b
    set a.name=b.name where a.id=b.id and a.name is null
    select id,(select name from tb where t.id =id group by id) as name, subject, score from tb t;都没有成功,我明白这两句的意思,但是实在找不出语法错误
      

  5.   


       建议你列出你的表结构,并提供测试数据以及基于这些测试数据的所对应正确结果。
       参考一下这个贴子的提问方式http://topic.csdn.net/u/20091130/20/8343ee6a-417c-4c2d-9415-fa46604a00cf.html
       
       1. 你的 create table xxx .. 语句
       2. 你的 insert into xxx ... 语句
       3. 结果是什么样,(并给以简单的算法描述)
       4. 你用的数据库名称和版本(经常有人在MS SQL server版问 MySQL)
       
       这样想帮你的人可以直接搭建和你相同的环境,并在给出方案前进行测试,避免文字描述理解上的误差。