I am trying to get the last status a customer had. By browsing examples, I have put together this query, which works:
SELECT table.Card,
table.Type,
table.Date,
ROW_NUMBER() OVER
(PARTITION by table.CARD ORDER BY table.date DESC, table.TYPE, table.DATE) rn
FROM table
WHERE table.Type = 'active' or table.Type = 'erased'
From there, I just need those records where rn=1, but as soon as I try to use itas a subquery as shown below, I get a syntaxis error:
SELECT * FROM (
SELECT table.Card,
table.Type,
table.Date,
ROW_NUMBER() OVER
(PARTITION by table.CARD ORDER BY table.date DESC, table.TYPE, table.DATE) rn
FROM table
WHERE table.Type = 'active' or table.Type = 'erased'
) WHERE rn=1
It must something simple I am just missing, but I am totally confused. Any help will be appreciated.
) AS x WHERE rn = 1;