SQL查询之谜

时间:2011-12-28 10:28:38

标签: sql

我有一张这样的表:

ID|Name|Issue|Location   
1 |01  |A    |.....  
2 |01  |B    |.....    
3 |02  |A    |.....  
4 |02  |B    |.....  
5 |02  |C    |.....   
6 |03  |A    |.....   

我想查询将返回每个的最大(问题)的id,名称,问题,位置 喜欢:

 2 |01  |B    |.....  
 5 |02  |C    |.....  
 6 |03  |A    |.....  

由于

1 个答案:

答案 0 :(得分:4)

select t.* 
from tab t 
join (
    select name, max(issue) as issue
    from tab
    group by name
) t1 on t.name = t1.name and t.issue = t1.issue