Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 4th, 2012  |  syntax: None  |  size: 0.49 KB  |  hits: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. postgreSQL select additional columns that aren't used in aggregate function
  2. PGError: ERROR:  column "users.id" must appear in the GROUP BY clause or be used in an aggregate function
  3.        
  4. PGError: ERROR:  column "users.id" must appear in the GROUP BY clause or be used in an aggregate function
  5.        
  6. SELECT users.*, a.num_deals FROM users, (
  7.     SELECT deal.id as dealid, COUNT(deals.id) AS num_deals
  8.     FROM deals
  9.     GROUP BY deal.id
  10. ) a where users.id = a.dealid
  11. ORDER BY a.num_deals DESC
  12. LIMIT 5