postgresql version of count query (2)