I am trying to write the following query in postgresql:
select name, author_id, count(1), (select count(1) from names as n2 where n2.id = n1.id and t2.author_id = t1.author_id ) from names as n1 group by name, author_id
This will certainly work on Microsoft SQL Server, but it is not at all on postegresql. I read its documentation a bit and it seems I can rewrite it as:
select name, author_id, count(1), total from names as n1, (select count(1) as total from names as n2 where n2.id = n1.id and n2.author_id = t1.author_id ) as total group by name, author_id
But this returns the following error in postegresql: "A subquery in FROM cannot refer to other relations of the same query level." So I'm stuck. Does anyone know how I can achieve this?
thank
sql sql-server postgresql subquery
Ricardo Lage Jun 09 '10 at 10:17 2010-06-09 10:17
source share