473,386 Members | 1,820 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Second Latest Date per Group

I have a table with these fields: employee ID, effective on date and supervisor ID.

Whenever an employee's supervisor changes, a new record is created with these fields. I need to retrieve the prior supervisor's ID for each employee. How would I pull the second latest effective on date for each employee?
Apr 19 '10 #1
3 2561
debasisdas
8,127 Expert 4TB
what is the query that you are working on ?
Apr 20 '10 #2
OraMaster
135 100+
@sugargirl
Please try to post sample data and expected output henceforth. If I understood your req. correctly then I suggest below SQL to get the expected result.

Expand|Select|Wrap|Line Numbers
  1. SELECT *
  2.   FROM (SELECT employee_id, effective_on_date, supervisor_id,
  3.                ROW_NUMBER () OVER (PARTITION BY employee_id ORDER BY effective_on_date DESC)
  4.                                                                        seqnum
  5.           FROM empsupv)
  6.  WHERE seqnum = 2
May 7 '10 #3
OraMaster,

Thanks so much for your post. The example you provided worked wonderfully!

Thanks!
May 11 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Jan Roland Eriksson | last post by:
For those interested, read and rip it up as you wish :-) ===== Archive-name: www/stylesheets/newsgroup-faq Posting-Frequency: twice a week (mondays and thursdays) Last-modified: July 20, 2004...
2
by: John Baker | last post by:
Hi: I have used this group a number of times simply because while the manuals for Access may show the technology, but most are really weak on how to apply it in special situations and the...
2
by: M.Stanley | last post by:
Hi, I have a problem..I'm doing a specific query where I'm joining fields from a table with appednded data (there are duplicate records, except for the date/time), and another query. I want the...
7
by: Scott Frankel | last post by:
Still too new to SQL to have run across this yet ... How does one return the latest row from a table, given multiple entries of varying data? i.e.: given a table that looks like this: color...
5
by: alanspamenglefield | last post by:
Hello group, I have an SQL statement which pulls data from a table as follows: " SELECT tblSites.sites_siteno, " & _ " tblSites.sites_sitename, " & _ " Sum(tblStockResults.stkr_result) AS...
24
by: clare at snyder.on.ca | last post by:
I have a SQL query I need to design to select name and email addresses for policies that are due and not renewed in a given time period. The problem is, the database keeps the information for every...
4
by: TGEAR | last post by:
Itemlookup table Field names : index_id (primary key), itemno, description. It has a child table, which is ItemPriceHistory table The relationship to the child table is one (parent table)-to-many...
7
by: Eugene | last post by:
Hi all, I have the following table Name Date Wish Valid Name is person's name, date defaults to getdate() and is never assigned directly (datetime field), Wish is some message, and...
6
by: piyushdabomb | last post by:
Hi All, Currently, I have a SQL query where I need to grab the SECOND latest date by group. COMPONENTID COMPLETIONDATE CBT_HAZCOM 02/26/2007 15:17:00 CBT_HAZCOM 07/31/2007 21:23:00 QS ...
2
by: piyushdabomb | last post by:
Hi All, Currently, I have a table with 2 columns COMPONENTID and COMPLETIONDATE COMPONENTID COMPLETIONDATE CBT_HAZCOM 02/26/2007 15:17:00 CBT_HAZCOM 07/31/2007 21:23:00 QS 02/12/2007...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.