Skip to content
Advertisement

GROUP BY all columns except two date fields and manipulate the date fields in query

I have a query that returns a bunch of columns including two date fields: START_DATE and END_DATE. I need to modify the query so that if all fields other than the dates are equal the rows are combined and the START_DATE is changed to the MIN date of all the combined rows and END_DATE is changed to the MAX date of all the combined rows?

Is this possible to do with CASE statements and subqueries?

SELECT 
    RA, 
    RA,
    START_DATE,
    END_DATE,
    RA, 
    GT,
    RG, 
    SR,   
    SR, 
    SR, 
FROM  RG,  RA,  SR,  GT
WHERE SR = RG
AND GT = RG
AND RA = 'asdH'
AND RA NOT IN ('G', 'W')
AND RA. = RG.
AND SR. = GT.;

Advertisement

Answer

This is an answer to your question, I dont have a lot of details so, a lot is left to imagination:

SELECT 
    RA.field1, 
    RA.field2,
    min(START_DATE) as START_DATE,
    max(END_DATE) as END_DATE,
    RA.field3, 
    GT.field4,
    RG.field5, 
    SR.field6,   
    SR.field7, 
    SR.field8, 
FROM  RG,  RA,  SR,  GT
WHERE SR = RG
AND GT = RG
AND RA = 'asdH'
AND RA NOT IN ('G', 'W')
AND RA. = RG.
AND SR. = GT.
group by 
    RA.field1, 
    RA.field2, 
    RA.field3, 
    GT.field4,
    RG.field5, 
    SR.field6,   
    SR.field7, 
    SR.field8
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement