0

我有表stud_idkey,name,standard,marks)。我想从每个中选择礼帽standard。以下查询会起作用吗?

SELECT DISTINCT( standard ), 
               stud_id, 
               name, 
               marks 
FROM   table 
WHERE  marks = Max(marks) 
GROUP  BY standard 
4

1 回答 1

3

如果你想要marks每个的顶部standard,那么你可以使用:

select t1.standard,
  t1.stud_id,
  t1.name,
  t1.marks
from table t1
inner join
(
  select standard,
    max(marks) TopMarks
  from table
  group by standard
) t2
  on t1.standard = t2.standard
  and t1.marks = t2.topmarks
于 2013-03-21T19:43:15.767 回答