Need to find the Max and Min dates using the results of a query. The following query is working but have to add additional code to find the Max/ Min dates based on its results (results of dates from last 2 AND statements). Using Oracle SQL Developer.
SELECT SO.COM_DATE, SO.RAISED_DATE, SE.SERV_NO, SO.OR_NO
FROM S_ORDER SO, S_SERV SE
WHERE SO.CU_NO='286243' AND SE.SERV_NO='69780'
AND SUBSTR (SE.ACCT_NO, 1,8)=SO.CU_NO
AND SO.RAISED_DATE +4/24 BETWEEN TO_DATE('2017-11-01','YYYY-MM-DD')
AND TO_DATE('2018-07-30','YYYY-MM-DD')
Tried to add the Max/ Min statements to the end but getting an Invalid Statement error. Thanks for any help.
Results of the query will therefore be:
COM_DATE | RAISED_DATE | SERV_NO | OR_NO
2018-07-05 | 2018-07-04 | 69780 | GHYUYR
2018-06-27 | 2018-06-08 | 69780 | HHUYTT
2018-03-10 | 2018-02-04 | 69780 | JJUHYT
Therefore, after the Min/ Max code added, the results should ONLY return:
COM_DATE | RAISED_DATE |
2018-07-05 (max)| 2018-02-04 (min)
SELECT
list includes two date columns (so.com_date
,so.raised_date
); which one do you wan theMIN
andMAX
of? I assume that your reference to "the last 2AND
statements" really means theso.raised_date +4/24 BETWEEN
part of the clause (syntax isX BETWEEN A AND B
). Are you looking for theMIN
andMAX
for each combination ofcom_date
,serv_no
, andor_no
, or for all rows returned? – RDFozz Jul 10 '18 at 17:51