I’ve just finished the intermediate part of the SQL course and everything was fine until I got to the Cumulative Project! I could not understand the syntax from exercises 6, 11, 12 and 13. To be more specific, I cracked my head to solve them but it just didn’t! Should I relax a little and go on or go back the whole path?
This code below is one I could not understand. I mean, the first part when it’s asking for the Name, Address and Phone is fine, but when it goes further and THIS:
(SELECT Borderline_High, High FROM recommended_values WHERE Lipid = “LDL”) rv — what’s “rv”?
active_patients.Name AS Name,
round(LDL) AS LDL,
active_patients.Address AS Address,
active_patients.Phone AS Phone
(SELECT Borderline_High, High FROM recommended_values WHERE Lipid = “LDL”) rv
JOIN active_patients ON panels.patient_ID = active_patients.ID
HAVING LDL >= rv.Borderline_High
ORDER BY LDL DESC;
This is another example:
COUNT(CASE WHEN (LDL >= rv.Borderline_High AND LDL < rv.High) THEN LDL END) AS Borderline_High,
COUNT(CASE WHEN LDL >= rv.High THEN LDL END) AS High
(SELECT Borderline_High, High FROM recommended_values WHERE Lipid = “LDL”) rv;
I’m still getting used to the CASE statement so it’s a little tricky. But again the “rv” which I have no idea what stands for.
I would really appreciate if someone could help a brother out.