Hi All, I have a Patient information table with ~50 million records. I need to check some samples for each year which may be in any order. Here are the sample date available in database "20090722", "20080817", ... "19980301". Also i have a primary-key column called "PID". My requirement is to get 2 or 3 samples for each year with a query.
I tried to get 2 samples for each year using sub-queries, i am not succeeded.
Any one in this forum have idea on this kind of requirement, If so please help me.
Guys i tried the following query in sql server and it worked find. But i need the query in MYSQL. Please help me out.
select pid,studydate
FROM (SELECT ROW_NUMBER() OVER ( PARTITION BY studydate ORDER BY pid DESC ) AS
'RowNumber', pid,studydate
FROM patient
) pt
WHERE RowNumber <= 2