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

Select Max values from queries for multiple Schedule_Number

I am trying to select the max for each Schedule_Number when Process
Description = 'Exit Cold Rinse'. In the following table, 2:00 and
4:00 should be returned for 12345_001 and 12345_002 respectively. I
have tried to join the two queries and would like to use the current
Schedule_Number as one of the criteria when determining the max.
Below is some code that I've used thus far? Does anyone have
suggestions?

*Schedule_Number * Process_Description * TMDT
*12345_001 * Exit Cold Rinse * 1/07/08 01:00:00 PM
*12345_001 * Enter Cold Rinse * 1/07/08 01:30:00 PM
*12345_001 * Exit Cold Rinse * 1/07/08 02:00:00 PM
*12345_002 * Enter Cold Rinse * 1/07/08 02:30:00 PM
*12345_002 * Exit Cold Rinse * 1/07/08 03:00:00 PM
*12345_002 * Enter Cold Rinse * 1/07/08 03:30:00 PM
*12345_002 * Exit Cold Rinse * 1/07/08 04:00:00 PM

Select *
From
(Select distinct Schedule_Number
From dbo.Process_Data
WHERE left(Schedule_Number,5) = '12345') as Query1
left join
(Select *
From dbo.Process_Data
Where TMDT =
(SELECT Max(TMDT)
FROM dbo.Process_Data
WHERE Process_Description = 'Exit Cold Rinse' and
Query1.Schedule_Number = Query2.Schedule_Number)) as Query2
on Query1.Schedule_Number=Query2.Schedule_Number
Jan 7 '08 #1
1 1522
Here is one way to get you the results:

SELECT Schedule_Number,
Process_Description,
MAX(TMDT) AS TMDT
FROM Process_Data
WHERE Process_Description = 'Exit Cold Rinse'
AND Schedule_Number LIKE '12345%'
GROUP BY Schedule_Number, Process_Description

Really no need for joins and the logic for Schedule_Number is converted to
utilize any index on the column.

HTH,

Plamen Ratchev
http://www.SQLStudio.com

Jan 8 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Guy Hocking | last post by:
Hi there, I have a problem in my ASP/SQL Server application i am developing, i hope you guys can help. I have a ASP form with list boxes populated by SQL tables. When a user selects a value...
11
by: Jeff Sandler | last post by:
I need a MySQL select statement as part of a PHP script. I want to find rows where a certain column either starts with or equals a user-supplied string. The string will be 1 or more characters in...
0
by: rayone | last post by:
Hi folks. I need advice. 2 options, which do you think is the better option to display/retrieve/report on the data. Keep in mind reporting (Crystal), SQL Performance, VB Code, usability,...
4
by: LD | last post by:
Is there a way in Access to store more than one value in a field that has been selected from a combo box? For example, if a combo box had three values that you can select, "One", "Two", and...
1
by: Grant McLean | last post by:
Hi First a simple question ... I have a table "access_log" that has foreign keys "app_id" and "app_user_id" that reference the "application_type" and "app_user" tables. When I insert into...
8
by: Chris A via AccessMonster.com | last post by:
I have an interesting problem that I have yet to come accross that I can't change data structure on because it is an export from filemaker I am reformatting for another dept. anyway. I have a table...
2
by: chrisale | last post by:
Hi All, I've been racking my brain trying to figure out some sort of Sub-Select mySQL statement that will create a result with multiple rows of averaged values over a years time. What I have...
31
by: louishong | last post by:
3rd time posting this as the first two simply disappeared! Here's the issue: We currently run an Access application in the West Coast for tracking resource centric data. For those located in the...
22
by: Rickster66 | last post by:
As Instructed this is a new thread regarding my original post: "Select Only 10 Columns Going Back" I'm sorry for the late response. I've been gathering up information and carefully with as much...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.