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

How Do I Query Latest Dates across Columns?

This is what I have right now,
Expand|Select|Wrap|Line Numbers
  1. SELECT  Project, S_on, P_on, H_on, A_on, I_on, 1_on, 2_on, 3_on, 4_on, Z_on, D_on, T_on, K_on, F_on, J_on, FINAL_on
  2. From DTable
  3. WHERE
  4. Class='XXX' AND 
  5. Project like 'Proj%' AND QA= 'ST'  AND FINAL_on is not NULL
  6.  
This will query make me a nice big table,
Expand|Select|Wrap|Line Numbers
  1. Proj1.xxx  DATE DATE DATE DATE DATE NULL DATE.... FINAL_onDATE
  2. Proj1.xxx  DATE DATE DATE DATE DATE DATE DATE.... FINAL_onDATE
  3. Proj1.xxx  DATE NULL DATE DATE NULL DATE DATE.... FINAL_onDATE
  4. Proj2.xxx  DATE DATE DATE DATE DATE DATE DATE.... FINAL_onDATE
  5. Proj2.xxx  DATE DATE DATE DATE DATE DATE DATE.... FINAL_onDATE
  6. Proj3.xxx  DATE DATE DATE NULL DATE DATE DATE.... FINAL_onDATE
  7.  
where date are in the form DD-MMM-YY (eg 24-JUN-08)

but what I want is the max (latest) date out of

S_on, P_on, H_on, A_on, I_on, 1_on, 2_on, 3_on, 4_on, Z_on, D_on, T_on, K_on, F_on, J_on


And then

FINAL_on - maxdate(above) which would return number of days

Then the avg of the days ( sum of days / count(projects) ) for each project


So I would want something like to be queried
Expand|Select|Wrap|Line Numbers
  1. PROJ  XXX   FINAL_on-maxdate   FINAL_on - maxdate / XXX
  2. A     3      100               33.33
  3. B     4      200               50
  4. C     3      33                11
  5. D     7      2                 ...
  6. E     8      365               ....
  7.  
I just need the first and last columns to be displayed. Thanks :)
Jul 17 '08 #1
1 1689
Atli
5,058 Expert 4TB
I don't really understand what the data in this table is used for.

What are all the X_on fields?

If each of the X_on fields are meant to represent a milestone, leading to a final "turn in" date, would it not be best to store these in a separate table?
Like:
Expand|Select|Wrap|Line Numbers
  1. Project
  2. -----------
  3. ProjectID Serial Primary Key
  4. ProjectName VarChar
  5. etc..
  6. ----------
  7.  
  8. MileStone
  9. ----------
  10. MSID Serial Primary Key
  11. MSName VarChar
  12. MSDate DateTime
  13. ProjectID BigInt References Project(ProjectID)
  14. ----------
  15.  
Then you could query that table, rather than having to manually check the various fields in the main table.
Jul 23 '08 #2

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

Similar topics

5
by: Jagdip Singh Ajimal | last post by:
I have 6 columns, all with dates within them, i.e. Proposed Start Date 1 Proposed Start Date 2 Proposed Start Date 3 Proposed Finish Date 1 Proposed Finish Date 2 Proposed Finish Date 3 ...
6
by: paii | last post by:
I have a table that stores job milestone dates. The 2 milestones I am interested in are "Ship Date" TypeID 1 and "Revised Ship Date" TypeID 18. All jobs have TypeID 1 only some jobs have TypeID 18....
8
by: Donna Sabol | last post by:
First, I should start by saying I am creating a database to be used by some very impatient, non-computer literate people. It needs to be seameless in it's operation from their point of view. I...
1
by: Mike Cooper | last post by:
Hi everyone, This is a tough one. I have a database full of solicitations, identifying a customer and recording initial call, first followup, second followup, etc. My boss want to be able to...
1
by: uspensky | last post by:
kind of a tough one i think but any help is appreciated. please try to stay away from T-SQL... I have a table with products and closing dates for each of 4 quarters and annual for several years...
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...
6
by: gerbski | last post by:
Hi all, I am relatively new to ADO, but up to now I got things working the way I wanted. But now I've run into somethng really annoying. I am working in MS Access. I am using an Access...
2
by: Bill | last post by:
I have a 200 record database that includes a date/time field, AnnivDate, for a wedding anniversary. AnnivDate has nulls and some incorrect year data. I have been creating the Access database...
2
by: Coxmg | last post by:
This would not let me post new threads for some reason, but heres my problem: I have several related tables. One table lists orders with due dates for SKUs while another table lists components of...
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: 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
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
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.