ID NAME SCORE
1  小明  89
2  小明  99
3  小罗  85
4  小李  56
5  小陈  74
6  小罗  90
7  小陈  59 显示结果:
ID NAME SCORE
2  小明  99
4  小李  56
5  小陈  74
6  小罗  90
表名TEST,如果名字NAME相同的话,请显示分数最大的项,小的记录筛选掉不显示。写出语句,即结果要求显示为??太晚了,晕了

解决方案 »

  1.   

    设表名为tb,代码如下:select a.*  from tb a,(select name,max(score) as score from tb group by name) b
     where a.score=b.score
      

  2.   


    这个写的太简单了,如果碰到 name不同的时候 score有多个相同 可以在条件后面加个 and a.name = b.name 
    但如果 碰到score多个相同 其中包括 name也有相同(如:他的数据中 2 小明 99 改为 2 小明 89 ),
    我是初学者 不懂该怎么写。
      

  3.   


    select a.*  from tb a,(select name,max(score) as score from tb group by name) b where a.name=b.name and a.score=b.score 
      

  4.   

    select max(id),name,max(score) from test group by name 很简单的问题
      

  5.   


    --1
    select A.* from TEST A
    inner join 
      (select [Name],Max(Score) as Score 
       from TEST
       group by [Name]) B
    on A.[Name]=B.[Name] and A.Score=B.Score--2
    select * from TEST A
    where not exists(select 1 from TEST where Name=A.Name and Score>A.Score)
      

  6.   


    如果这样,我修改为:select * from tb a where id in(select top 1 id from tb where name=a.name order by score desc) order by name如果想把相同分数得并列列出,用:select * from tb a where score in(select top 1 score from tb where name=a.name order by score desc) order by name
      

  7.   

    select id,name,max(score) from test group by name,id
      

  8.   

    select max(id),name,score 
    from test 
    group by name
    having score=max(score)
      

  9.   

    select id,name,score 
    from test 
    group by name 
    having score=max(score)初学的,改了又改呵呵