Advertisement
clydeee

SQL Exam 1

Aug 22nd, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 0.56 KB | None | 0 0
  1. SELECT username, email, COUNT(b.userid) AS log_count , temp1.max_count
  2.     FROM i_user a
  3.    LEFT JOIN i_user_login_logs b
  4.      ON a.userid = b.userid
  5.    LEFT JOIN (
  6.     SELECT COUNT(b.userid) AS max_count
  7.     FROM i_user a
  8.    LEFT JOIN i_user_login_logs b
  9.      ON a.userid = b.userid
  10.   WHERE username <> 'Admin'
  11.   GROUP BY a.userid
  12.   ORDER BY max_count DESC
  13.   LIMIT 1
  14.    ) AS temp1
  15.     ON temp1.max_count > 1
  16.   WHERE username <> 'Administrator'
  17.     AND isactive = 1
  18.   GROUP BY a.userid
  19.    
  20.   HAVING (log_count = temp1.max_count)
  21.  
  22.   ORDER BY log_count DESC
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement