k***t 发帖数: 276 | 1 没时间看SQL了,谁给个答案。谢。
SQL 一个table, 一个employee 在不同的timestamp下会有不同的salary
Employee Salary TimeStamp
Find Employee A's salary with largest time stamp |
I*******x 发帖数: 20 | 2 select salary from Salary where Employee=A order by TimeStamp desc limit 1;
【在 k***t 的大作中提到】 : 没时间看SQL了,谁给个答案。谢。 : SQL 一个table, 一个employee 在不同的timestamp下会有不同的salary : Employee Salary TimeStamp : Find Employee A's salary with largest time stamp
|
l*****a 发帖数: 14598 | 3 WHY NOT USE MAX(TIMESTAMP)
【在 I*******x 的大作中提到】 : select salary from Salary where Employee=A order by TimeStamp desc limit 1;
|
k***t 发帖数: 276 | 4 查 MAX sample 凑了一个。
SELECT Salary FROM tablename WHERE Employee=A AND Timestamp =
(SELECT MAX(Timestamp) FROM tablename WHERE Employee=A)
【在 l*****a 的大作中提到】 : WHY NOT USE MAX(TIMESTAMP)
|
l*****a 发帖数: 14598 | 5 search sample for HAVING please
【在 k***t 的大作中提到】 : 查 MAX sample 凑了一个。 : SELECT Salary FROM tablename WHERE Employee=A AND Timestamp = : (SELECT MAX(Timestamp) FROM tablename WHERE Employee=A)
|
k***t 发帖数: 276 | 6 select salary from tablename where employee=A and having timestamp=max(timestamp)
如果不对,请给正确答案。谢。
【在 l*****a 的大作中提到】 : search sample for HAVING please
|
w**z 发帖数: 8232 | 7 you may run the execution plan and see what is the difference between the
two sql. Both should return the correct result though. |
w**z 发帖数: 8232 | 8 The popular question for SQL is outer join and group by, Look up those two
concepts |
B*****g 发帖数: 34098 | 9 http://docs.oracle.com/cd/B28359_01/server.111/b28286/functions
http://www.mitbbs.com/article_t2/Database/31148641.html
【在 k***t 的大作中提到】 : 没时间看SQL了,谁给个答案。谢。 : SQL 一个table, 一个employee 在不同的timestamp下会有不同的salary : Employee Salary TimeStamp : Find Employee A's salary with largest time stamp
|