Advertisement
Guest User

Untitled

a guest
May 26th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 1.25 KB | None | 0 0
  1. # This is a query to get statistics on what days a specific user is playing games, on average of the past 4 weeks
  2.  
  3. SELECT
  4.     DATE_FORMAT(startDate, '%W') AS day,
  5.     SUM(TIMESTAMPDIFF(SECOND, startDate, endDate)) / 4 AS time
  6.   FROM playtime
  7.     WHERE userID=?
  8.     AND startDate > NOW() - INTERVAL 4 WEEK
  9.   GROUP BY DATE_FORMAT(startDate, '%W')
  10.   ORDER BY time DESC
  11.  
  12. # This is a query to get the top played games on a server
  13.  
  14. SELECT
  15.     game,
  16.     SUM(TIMESTAMPDIFF(SECOND,startDate, IFNULL(endDate, NOW()))) AS time,
  17.     COUNT(DISTINCT userID) AS count
  18.   FROM
  19.       playtime
  20.   WHERE
  21.       userID IN (SELECT userID FROM userGuilds WHERE guildID=?)
  22.  
  23.       # This is optional, but may be useful if you would add a filter for games/software/blocked/unknown presences
  24.       AND game IN (SELECT game FROM knownGames WHERE type=?)
  25.  
  26.   GROUP BY game
  27.   ORDER BY time DESC
  28.  
  29. # This is a query to get a playtime chart for a specific server and a specific game
  30.  
  31. SELECT
  32.   DATE_FORMAT(startDate, '%M %d %Y') AS day,
  33.     SUM(TIMESTAMPDIFF(MINUTE, startDate, IFNULL(endDate, NOW()))) AS time
  34.   FROM playtime
  35.   WHERE
  36.     game=?
  37.     AND userID IN (SELECT userID FROM userGuilds WHERE guildID=?)
  38.   GROUP BY DATE_FORMAT(startDate, '%M %d %Y')
  39.   ORDER BY startDate
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement