Advertisement
Rafael_Yuki

Untitled

Feb 29th, 2024
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. SELECT
  2.     e.UsuarioID,
  3.     u.Nome,
  4.     COUNT(e.UsuarioID) AS Total_Emprestimos
  5. FROM
  6.     Emprestimos e
  7. INNER JOIN
  8.     Usuarios u ON e.UsuarioID = u.UsuarioID
  9. GROUP BY
  10.     e.UsuarioID,
  11.     u.Nome
  12. ORDER BY
  13.     Total_Emprestimos DESC
  14. LIMIT 5;
  15.  
  16.  
  17. CREATE OR REPLACE VIEW Usuarios_Mais_Ativos AS
  18. SELECT
  19.     e.UsuarioID,
  20.     u.Nome,
  21.     COUNT(e.UsuarioID) AS Total_Emprestimos
  22. FROM
  23.     Emprestimos e
  24. INNER JOIN
  25.     Usuarios u ON e.UsuarioID = u.UsuarioID
  26. GROUP BY
  27.     e.UsuarioID,
  28.     u.Nome
  29. ORDER BY
  30.     Total_Emprestimos DESC
  31. LIMIT 5;
  32.  
  33. SELECT * FROM Usuarios_Mais_Ativos;
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement