473,386 Members | 1,733 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.

Nested Select of Min and Max

Ker
I have a query that works great. It gives me the min for multiple
fields.
Within this query, I also need to get the max of some fields too.

I currently have output of
Date Name Min Start
9/1/03 Walker Rhines 7:00AM

I also need Max such as Max End 3:00PM

My question is how to attach the max selection to this syntax wise.

Thanks, Ker
SELECT SubJobTable.Date AS Expr1, SubJobTable.EmployeeName AS Expr2,
Min(a.testforum) AS [min]
FROM (SELECT Min([LoadUpStart]) AS testforum
FROM SubJobTable
WHERE Expr1 = [SubJobTable].[Date] AND Expr2 =
[SubJobTable].[EmployeeName]
union all
SELECT Min([TravelToStart])
FROM SubJobTable
WHERE Expr1 = [SubJobTable].[Date] AND Expr2 =
[SubJobTable].[EmployeeName]
union all
SELECT Min([TravelFromStart])
FROM SubJobTable
WHERE Expr1 = [SubJobTable].[Date] AND Expr2 =
[SubJobTable].[EmployeeName]
union all
SELECT Min([JobStart])
FROM SubJobTable
WHERE Expr1 = [SubJobTable].[Date] AND Expr2 =
[SubJobTable].[EmployeeName]
union all
SELECT Min([AdminStart])
FROM SubJobTable
WHERE Expr1 = [SubJobTable].[Date] AND Expr2 =
[SubJobTable].[EmployeeName]
union all
SELECT Min([NurseryStart])
FROM SubJobTable
WHERE Expr1 = [SubJobTable].[Date] AND Expr2 =
[SubJobTable].[EmployeeName]
union all
SELECT Min([OtherStart])
FROM SubJobTable
WHERE Expr1 = [SubJobTable].[Date] AND Expr2 =
[SubJobTable].[EmployeeName]
union all
SELECT Min([ShopStart])
FROM SubJobTable
WHERE Expr1 = [SubJobTable].[Date] AND Expr2 =
[SubJobTable].[EmployeeName]
union all
SELECT Min([DesignStart])
FROM SubJobTable
WHERE Expr1 = [SubJobTable].[Date] AND Expr2 =
[SubJobTable].[EmployeeName]
union all
SELECT Min([PlantMatPUDelStart])
FROM SubJobTable
WHERE Expr1 = [SubJobTable].[Date] AND Expr2 =
[SubJobTable].[EmployeeName]) AS a;
Nov 12 '05 #1
3 6706
SELECT SubJobTable.Date AS Expr1, SubJobTable.EmployeeName AS Expr2,
Min(a.testforum) AS [min], Max(a.MAXtestforum) AS [max]
FROM (SELECT Min([LoadUpStart]) AS testforum, Max([LoadUpStart]) AS
MAXtestforum
....
union all
SELECT Min([TravelToStart]), Max([TravelToStart])
....
union all
SELECT Min([TravelFromStart]), Min([TravelFromStart])
....

"Ker" <ed********@charter.net> escreveu na mensagem
news:23**************************@posting.google.c om...
I have a query that works great. It gives me the min for multiple
fields.
Within this query, I also need to get the max of some fields too.

I currently have output of
Date Name Min Start
9/1/03 Walker Rhines 7:00AM

I also need Max such as Max End 3:00PM

My question is how to attach the max selection to this syntax wise.

Thanks, Ker
SELECT SubJobTable.Date AS Expr1, SubJobTable.EmployeeName AS Expr2,
Min(a.testforum) AS [min]
FROM (SELECT Min([LoadUpStart]) AS testforum
FROM SubJobTable
WHERE Expr1 = [SubJobTable].[Date] AND Expr2 =
[SubJobTable].[EmployeeName]
union all
SELECT Min([TravelToStart])
FROM SubJobTable
WHERE Expr1 = [SubJobTable].[Date] AND Expr2 =
[SubJobTable].[EmployeeName]
union all
SELECT Min([TravelFromStart])
FROM SubJobTable
WHERE Expr1 = [SubJobTable].[Date] AND Expr2 =
[SubJobTable].[EmployeeName]
union all
SELECT Min([JobStart])
FROM SubJobTable
WHERE Expr1 = [SubJobTable].[Date] AND Expr2 =
[SubJobTable].[EmployeeName]
union all
SELECT Min([AdminStart])
FROM SubJobTable
WHERE Expr1 = [SubJobTable].[Date] AND Expr2 =
[SubJobTable].[EmployeeName]
union all
SELECT Min([NurseryStart])
FROM SubJobTable
WHERE Expr1 = [SubJobTable].[Date] AND Expr2 =
[SubJobTable].[EmployeeName]
union all
SELECT Min([OtherStart])
FROM SubJobTable
WHERE Expr1 = [SubJobTable].[Date] AND Expr2 =
[SubJobTable].[EmployeeName]
union all
SELECT Min([ShopStart])
FROM SubJobTable
WHERE Expr1 = [SubJobTable].[Date] AND Expr2 =
[SubJobTable].[EmployeeName]
union all
SELECT Min([DesignStart])
FROM SubJobTable
WHERE Expr1 = [SubJobTable].[Date] AND Expr2 =
[SubJobTable].[EmployeeName]
union all
SELECT Min([PlantMatPUDelStart])
FROM SubJobTable
WHERE Expr1 = [SubJobTable].[Date] AND Expr2 =
[SubJobTable].[EmployeeName]) AS a;

Nov 12 '05 #2
I tried this like you said. It's close but still doesn't produce the
correct output.

The output is
9/1/03 walker white 7am 7pm
9/2/03 Angie mace 7am 7pm (should be 6am 3pm)
9/2/03 Kenneth mere 7am 7pm (should be 8am 4pm)
It's listing the right dates and employees but listed the same min and
max everytime
When I run the query, it asks me for Expr1 and Expr 2. I only want it
to ask me date range and automatically list all my employees from
SubJobTable with a record with their name in it where date is within the
range. Thanks for all your help!

Here's the query revised with your modifications.

SELECT SubJobTable.Date AS Expr1, SubJobTable.EmployeeName AS Expr2,
Min(a.testforum) AS [min], Max(a.maxtestforum) AS [max]
FROM [SELECT Min([LoadUpStart]) AS testforum, Max([LoadUpEnd]) AS
maxtestforum
FROM SubJobTable
WHERE Expr1 = [SubJobTable].[Date] AND Expr2 =
[SubJobTable].[EmployeeName]
union all
SELECT Min([TravelToStart]), Max([TravelToEnd])
FROM SubJobTable
WHERE Expr1 = [SubJobTable].[Date] AND Expr2 =
[SubJobTable].[EmployeeName]
union all
SELECT Min([TravelFromStart]), Max([TravelFromEnd])
FROM SubJobTable
WHERE Expr1 = [SubJobTable].[Date] AND Expr2 =
[SubJobTable].[EmployeeName]
union all
SELECT Min([JobStart]), Max([JobEnd])
FROM SubJobTable
WHERE Expr1 = [SubJobTable].[Date] AND Expr2 =
[SubJobTable].[EmployeeName]
union all
SELECT Min([AdminStart]) , Max([AdminEnd])
FROM SubJobTable
WHERE Expr1 = [SubJobTable].[Date] AND Expr2 =
[SubJobTable].[EmployeeName]
union all
SELECT Min([NurserySt! art]), Max([NurseryEnd])
FROM SubJobTable
WHERE Expr1 = [SubJobTable].[Date] AND Expr2 =
[SubJobTable].[EmployeeName]
union all
SELECT Min([OtherStart]), Max([OtherEnd])
FROM SubJobTable
WHERE Expr1 = [SubJobTable].[Date] AND Expr2 =
[SubJobTable].[EmployeeName]
union all
SELECT Min([ShopStart]), Max([ShopEnd])
FROM SubJobTable
WHERE Expr1 = [SubJobTable].[Date] AND Expr2 =
[SubJobTable].[EmployeeName]
union all
SELECT Min([DesignStart]), Max([DesignEnd])
FROM SubJobTable
WHERE Expr1 = [SubJobTable].[Date] AND Expr2 =
[SubJobTable].[EmployeeName]
union all
SELECT Min([PlantMatPUDelStart]), Max([PlantMatPUDelEnd])
FROM SubJobTable
WHERE Expr1 = [SubJobTable].[Date] AND Expr2 =
[SubJobTable].[EmployeeName]]. AS a, SubJobTable
GROUP BY SubJobTable.Date, SubJobTable.EmployeeName;

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #3
I haven't received a response to my thread, can someone please look at
this.

Thanks,
Ker

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #4

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

Similar topics

4
by: dw | last post by:
Hello all. We're doing a site with teams and their members. We've got a page where we need to display people according to who belongs to a which team. I've heard that nested loops are bad, but...
2
by: Forgone Conclusion | last post by:
Hi, I have a View that groups and sums up totals. This View is then nested within in another View and used (it needs to be done like this). What i need to do is to be able to vary the records...
3
by: WGW | last post by:
Though I am a novice to MS SQL server (2000 I believe), I can do almost! everything I need. Maybe not efficiently, but usefully. However, I have a problem -- a complex query problem... I can...
12
by: Jeff Lanfield | last post by:
First of all, I apologize if coalescing is not the right term to describe my problem. I have a tree where each node has the same set of attributes (is the same entity) but child nodes should...
7
by: Anthony Robinson | last post by:
Have been encountering an odd issue. Every now and again, certain packages of stored procedures just become invalid. I'm aware that dropping or altering an underlying table would render a package...
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...
1
by: Thu | last post by:
Hi, I create a Dataset to link three tables in my Access database. E.g. The three tables are , , . I then create 2 DataRelations, 1st relation (Order_Cust_Rel) links and using CustomerID field...
25
by: GY2 | last post by:
I writing some documentation and I want to describe a common code structure which is used to step through all the items in a collection (e.g. each file in a subdirectory) while applying more and...
3
by: Frank Swarbrick | last post by:
I was just messing around trying to learn things and attempted the following: select brch_nbr , sum(case when post_flag != 'P' then amount else 0 end) as sum_amount from film.film_transactions...
9
by: P3Eddie | last post by:
Hello all! I don't know if this can even be done, but I'm sure you will either help or suggest another avenue to accomplish the same. My problem may be a simple find duplicates / do something...
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: 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: 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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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.