473,396 Members | 2,004 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,396 software developers and data experts.

SQL select help

I need to select the most recent record within a date range for each combination of two ids. In other words, given the folowing table:

ID1 ID2 MyDate MyNum
1005 27 9/12/06 13:00 100
1001 21 9/12/06 13:00 500
1005 27 9/12/06 12:00 300
1004 21 9/12/06 12:00 200
1001 11 9/12/06 12:00 1000
1001 27 9/12/06 12:00 2000
1001 21 9/12/06 12:00 3000
1005 27 8/19/06 13:00 100

I need the records for the most recent MyDate in the 8hours ending with 9/12/06 13:00 for each ID1 and ID2 pair. Going back to the table, here are what the results should be:

ID1 ID2 MyDate MyNum
1005 27 9/12/06 13:00 100 I Need
1001 21 9/12/06 13:00 500 I Need
1005 27 9/12/06 12:00 300 NO - there's a more recent record
1004 21 9/12/06 12:00 200 I Need
1001 11 9/12/06 12:00 1000 I Need
1001 27 9/12/06 12:00 2000 I Need
1001 21 9/12/06 12:00 3000 NO - there's a more recent record
1005 27 8/19/06 13:00 100 NO - not in the date range

The following select statement gets me the most 13:00 submissions but not the others.
SELECT ID1, ID2, MyDate, MyNum
FROM T
WHERE (MyDate = (
SELECT MAX(MyDate) FROM T WHERE
MyDate >= TO_DATE('09/12/2006 05:00','MM-DD-YYYY HH24:MI') AND
MyDate <= TO_DATE('09/12/2006 13:00','MM-DD-YYYY HH24:MI')))

Any suggestions? Thank you.
Sep 12 '06 #1
0 1623

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

Similar topics

1
by: prabu | last post by:
Hello all, I am new to Python,And this is my first post.I have installed "Fsh",an Opensource Product ,very similar to SSH on my HP-UX B.11.22 U ia64(IPF).It has Python dependency.The problem is...
21
by: John Fabiani | last post by:
Hi, I'm a newbie and I'm attempting to learn howto create a select statement. When I use >>> string1='18 Tadlock Place' >>> cursor.execute("SELECT * FROM mytest where address = %s",string1) All...
3
by: Tcs | last post by:
My backend is DB2 on our AS/400. While I do HAVE DB2 PE for my PC, I haven't loaded it yet. I'm still using MS Access. And no, I don't believe this is an Access question. (But who knows? I...
4
by: Terencetrent | last post by:
I having been using Access '97/2002 for about 4 years now and have never really had the need or the time to learn visual basic. Well, I think the time has finally come. I need help with Visual...
2
by: Chris Plowman | last post by:
Hi all, I was wondering if anyone can help me with a really annoying problem I have been having. I made a derived datagrid class that will select the row when a user clicks anywhere on a cell...
1
by: bpforte | last post by:
Hello, I need help with building query, basically I need to select all records from one table that don't exists in second table with status 1, but they can exists in second table with status 0, to...
9
by: xmlhelp | last post by:
stuff.XSL: <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:param name="uid"/> <xsl:template match="/"> parameter...
3
by: Patrick | last post by:
Hi All, I'm new to all this and I'm back for more help. I am working with global variables. I'm trying to make my xls just display the data for the defined <moorname>. In my example I am using...
9
chunk1978
by: chunk1978 | last post by:
hey everyone, i've been trying to solve this problem for 2 days straight, with no end in sight. i would greatly appreciate anyone's help. EXPLANATION: There are 3 Select Menus. The 1st and...
6
by: dhek | last post by:
Hi, I have a very simple issue: for simplicity lets say I have 2 tables, A and B. - Table A contains 5 fields. Amongst these there is a 'id'-field which is but a reference to table B. - Table...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.