Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2006-06-15 : 08:29:45
|
barkie writes "We recently converted our salary history to reflect hourly wage not bi-weekly wage but kept all the old data for historical purposes. The application uses an id for the staff member and a sub_id to reflect the last entered value. The salary rate could go up or down over time. So, I'd like a query that returns the last entered transaction [ max(sub_id) seems logical) and the other values in the row too.table salhistoryid = integersub_id = integersal_rate = currencyid sub_id sal_rate (return this row?)1 56 22181 122 22321 3613 22.15 y12 88 232212 133 210012 3720 22.3312 3752 21.17 y66 156 10.10 y3220 1810 22663220 1922 28163220 5620 62.19 y==================================I know you are on top of this one...barkie" |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-06-15 : 08:35:35
|
[code]select z.id, salhistory.sub_id, salhistory.sal_ratefrom ( SELECT id, MAX(sub_id) subid FROM salhistory ) zinner join salhistory on salhistory.id = z.id and salhistory.subid = z.sub_id[/code]Peter LarssonHelsingborg, Sweden |
|
|
|
|
|