如何获取查询结果中的最大日期

时间:2013-12-18 06:29:55

标签: sql

我的查询结果如下:

empName project leavedate
abc     pjt1    10/10/2013
abc     pjt1    10/12/2013
abc     pjt2    10/10/2011

基于上面的查询结果,我想获得他已经离开的每个项目的最新日期。它不是表格,它是查询结果。

3 个答案:

答案 0 :(得分:0)

SELECT MAX(leavedate) FROM my_table_; 

http://www.w3schools.com/sql/sql_func_max.asp

答案 1 :(得分:0)

SELECT t1.empName, t1.project, t1.leavedate
FROM <yourTable> t1 
WHERE NOT EXISTS (SELECT * FROM <yourTable> t2 
                  WHERE t1.project = t2.project AND t2.leavedate > t1.leavedate)

答案 2 :(得分:0)

试一试:

  SELECT empName, project, MAX(leavedate)
    FROM mytable
GROUP BY project;