Subject | Re: [firebird-support] Getting the Bigger Value of two fields in one field |
---|---|
Author | Helen Borrie |
Post date | 2005-05-20T01:38:56Z |
At 10:53 PM 19/05/2005 +0200, you wrote:
SELECT
"Treatments"."PatientID',
"Treatments"."TreatmentID',
case
when ((MAX("Treatments"."WorkStartDate") >= MAX("TreatmentDetails"."TreatmentDetailDate")
or (MAX("TreatmentDetails"."TreatmentDetailDate") is null))
then MAX("Treatments"."WorkStartDate")
else MAX("TreatmentDetails"."TreatmentDetailDate") end
as "LastTreatmentDate"
FROM "Treatments"
LEFT JOIN "TreatmentDetails"
ON "Treatments"."TreatmentID" = "TreatmentDetails"."TreatmentID"
GROUP BY 1, 2
(or whatever you need...)
./hb
>Hi.Assuming some kind of grouping, e.g. PatientID and/or TreatmentID,
>
>I have this Query:
>
>SELECT
> MAX("Treatments"."WorkStartDate") "WorkStartDate",
> MAX("TreatmentDetails"."TreatmentDetailDate") "TreatmentDetailDate"
>FROM
> "Treatments" LEFT OUTER JOIN "TreatmentDetails"
> ON "Treatments"."TreatmentID" = "TreatmentDetails"."TreatmentID"
>
>Is there away to get the bigger Date of those two fields in one fields and not I two as I did ?
SELECT
"Treatments"."PatientID',
"Treatments"."TreatmentID',
case
when ((MAX("Treatments"."WorkStartDate") >= MAX("TreatmentDetails"."TreatmentDetailDate")
or (MAX("TreatmentDetails"."TreatmentDetailDate") is null))
then MAX("Treatments"."WorkStartDate")
else MAX("TreatmentDetails"."TreatmentDetailDate") end
as "LastTreatmentDate"
FROM "Treatments"
LEFT JOIN "TreatmentDetails"
ON "Treatments"."TreatmentID" = "TreatmentDetails"."TreatmentID"
GROUP BY 1, 2
(or whatever you need...)
./hb