0

I am looking for help converting my MySQL query to work in PostgreSQL. This is a query on the model of RoR application. Any help is appreciated.

SELECT * FROM( 
   SELECT @row := @row + 1 AS rownum, id, device_id, name, quarterly 
   FROM (SELECT @row :=0) r, recurrent_tests 
   WHERE device_id = "+self.id.to_s+" AND quarterly = 1
   ORDER BY name ASC
) ranked 
WHERE (rownum-1) % 4 = "+(i-1).to_s)
1

1 Answer 1

2
select *
from (
   select row_number() over (order by name asc) as rownum,
          id, 
          device_id, 
          name,
          quarterly
   from recurrent_tests
) t
where rownum - 1 % 4 = ...

For more details on window functions (the over (...) clause) please see the manual:
http://www.postgresql.org/docs/current/static/tutorial-window.html

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.