SQL syntax to check values in a group

UDA
Enthusiast

SQL syntax to check values in a group

Hi All,

I am trying to verify a table group by say ss_id, and say it returns 10 rows (same ss_id). Now I am trying to verify whether 10th row value > 9th row, 9th row > 8th row ...

I need some feedback on way of resolving the problem.

with regards,
rlaskar
1 REPLY
Enthusiast

Re: SQL syntax to check values in a group

Hi,

Look for the "PREV_VALUE" & "RESULT" logic in below query.

SEL
SS_ID,
CURR_VALUE,
(SUM(CURR_VALUE)OVER(ROWS 1 PRECEDING) - CURR_VALUE) "PREV_VALUE" ,
(CASE WHEN CURR_VALUE > PREV_VALUE THEN 'TRUE'
WHEN CURR_VALUE = PREV_VALUE THEN 'EQUAL'
ELSE 'FALSE'
END) "RESULT"
FROM(
SEL
SS_ID,
SUM(X) "CURR_VALUE"
FROM XYZ
GROUP BY 1
)A

Is this solution right for your requirement?