I have 2 tables:
Table: PatientsUpdates
Table: TextMaster
I need the final result:
The final result is the current status of all patients of the gender reassignment surgery section in a hospital, but title of a patient's name is selected from TextMaster table.
From this SQL:
SELECT DISTINCT "PatientID",
FIRST_VALUE("TextSource")
OVER (PARTITION BY "PatientID" ORDER BY CASE WHEN "TextSource" IS NOT NULL THEN "EffectiveDate" END DESC) "TextSource",
FIRST_VALUE("TextGroup")
OVER (PARTITION BY "PatientID" ORDER BY CASE WHEN "TextGroup" IS NOT NULL THEN "EffectiveDate" END DESC) "TextGroup",
FIRST_VALUE("TextIndex")
OVER (PARTITION BY "PatientID" ORDER BY CASE WHEN "TextIndex" IS NOT NULL THEN "EffectiveDate" END DESC) "TextIndex",
FIRST_VALUE("FirstName")
OVER (PARTITION BY "PatientID" ORDER BY CASE WHEN "FirstName" IS NOT NULL THEN "EffectiveDate" END DESC) "FirstName",
FIRST_VALUE("LastName")
OVER (PARTITION BY "PatientID" ORDER BY CASE WHEN "LastName" IS NOT NULL THEN "EffectiveDate" END DESC) "LastName"
FROM "PatientsUpdates";
I have got this query result:
Can you please help teach me with the correct SQL to replace TextSource, TextGroup and TextIndex with TextDetail or better SQL than as shown above?