Advertisement
ILyaCyclone

Untitled

Mar 20th, 2019
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 0.45 KB | None | 0 0
  1. SELECT t.id, t.name, t.votes
  2. FROM (
  3.        SELECT r.id, r.name, COUNT(v.id_user) AS votes
  4.        FROM restaurants r,
  5.             user_votes v
  6.        WHERE v.id_restaurant = r.id
  7.          AND v.DATE = ?1
  8.        GROUP BY r.id, r.name
  9.      ) t
  10. WHERE t.votes =
  11.       (SELECT MAX(votes)
  12.        FROM (SELECT COUNT(v2.id_user) AS votes
  13.              FROM user_votes v2
  14.              WHERE v2.DATE = ?1
  15.              GROUP BY v2.id_restaurant))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement