SQL,选择max date,如果两个结果具有max date,则选择具有最大权重的结果

SQL,选择max date,如果两个结果具有max date,则选择具有最大权重的结果,sql,Sql,我的SQL请求应该给我第4行 ID | DATE_I | Weight 1 | 10/04/2014 08:13:05 | 10 2 | 02/04/2014 08:13:05 | 15 3 | 08/04/2014 08:13:05 | 10 4 | 13/04/2014 08:13:05 | 12 5 | 13/04/2014 08:13:05 | 10 试试这个: select id, max(DATE_I) from MyTable

我的SQL请求应该给我第4行

ID | DATE_I                 | Weight
1  | 10/04/2014 08:13:05  | 10
2  | 02/04/2014 08:13:05  | 15
3  | 08/04/2014 08:13:05  | 10
4  | 13/04/2014 08:13:05  | 12
5  | 13/04/2014 08:13:05  | 10
试试这个:

select id, max(DATE_I)
from MyTable m
where m.Weight > (select m2.Weight from MyTable m2 having max(DATE_I)); 

DATE\u I
Weight
降序排列您的行,并获得第一行

SQL Server的示例代码

select y.ID, x.maxdate, x.maxweight
from 
(
  select a.maxdate, Max(b.Weight) as maxweight
  from 
  (
    select max(date_I) as maxdate
    from mytable
  )a 
  inner join mytable b on a.maxdate = b.date_I
  group By a.maxdate
) x inner join mytable y on x.maxweight = y.weight

怎么了你能解释一下你想要什么吗?并提供一个SQLFiddle?你使用什么mysql、sql server?你是否面临任何错误?我看不到日期。只是奇怪的字符串。
select top (1) ID, DATE_I, Weight
from mytable
order by DATE_I desc, Weight desc;