I have a table with these rows:
How can I write a query that will return a result set looking like this:
I’d really appreciated it. Also this needs to be done in SQL Server for context.
I tried the normal dense_rank() over (partition by name order by date)
, but did not get the result I need.
New contributor
ITSoftwareDeveloper is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
5
SELECT *,
DENSE_RANK() OVER (ORDER BY CASE Pet
WHEN 'dog' THEN 1
WHEN 'cat' THEN 2
WHEN 'fish' THEN 3
ELSE 4 END ) as Pet_Number
FROM Example
fiddle