SELECT num FROM test
LEFT JOIN text ON test.code = text.codeFK
WHERE state = 'O'

ORDER BY test.num DESC;
GRP calculation on its on

select t.*,
(select count(distinct t2.num)
from test t2
where t2.num <= t.num
) as grp
from test t ORDER BY GRP;
But my question is how to get GRP column with above join query? So, the grp column will be calculated only on the results based on WHERE statement and not the whole table test.

I tried below but it gives me an error:

SELECT num FROM test
LEFT JOIN text ON test.code = text.codeFK
WHERE state = 'O'

Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.