Hello, I have this table that I am trying to compare two different values in the same field basically checking if one is greater than the other based on another field that is used as a date. The objective is we are checking to see if test scores have increased from one year to the next. The test values are stored in table called OT and the date field (which isn't a datetime type field btw) is TA. So im thinking case statements nested in cte's??? this is what I've been working on returns no results???. ThanksWITH cte1 ( a, PID, LF, PT) AS ( SELECT PID, LF, TST.PT, TST.OT FROM TST INNER JOIN STU ON TST.PID = STU.ID WHERE TST.TA LIKE '%12' AND TST.ID = 'CELDT' AND STU.SC = 12 ), cte2 ( b, PID, LF, PT) AS ( SELECT PID, LF, TST.PT, TST.OT AS b FROM TST INNER JOIN STU ON TST.PID = STU.ID WHERE TST.TA LIKE '%13' AND STU.LF = '3' AND TST.PT = 0 AND TST.ID = 'CELDT' AND STU.SC = 12 ) SELECT c1.PID, a, b, CASE WHEN b > a THEN 'Yes' ELSE 'No' END AS outcome FROM cte1 c1 LEFT JOIN cte2 c2 ON c1.PID = c2.PID WHERE c1.LF = '3' AND c1.PT = 0
I want the table to look like:TST.PID | a | b | Outcome------------------------1234 | 2 | 3 | YesCartesian Yak