Advertisement
Guest User

Untitled

a guest
May 26th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 1.68 KB | None | 0 0
  1. // This is a query to get the playtime of a specific game of a user
  2.  
  3. SELECT
  4.     SUM(IF(
  5.         startDate > ?,
  6.         TIMESTAMPDIFF(SECOND,startDate, IFNULL(endDate, NOW())),
  7.         0)) AS time
  8. FROM
  9.     playtime
  10. WHERE
  11.     userID = ?
  12.     AND game = ?
  13.  
  14.  
  15. // This is a query to get the top played games of a user
  16.  
  17. SELECT
  18.     game,
  19.     SUM(TIMESTAMPDIFF(SECOND,startDate, IFNULL(endDate, NOW()))) AS time
  20. FROM
  21.     playtime
  22. WHERE
  23.     userID = ?
  24. GROUP BY game
  25. ORDER BY time DESC
  26. LIMIT 10
  27.  
  28. // If you want some kind of award system here is a query for the role awards of TimePlayed
  29. // Just to be clear: the userGuilds table contains every guild ID and member ID of everyone sharing a server with the bot,
  30. // so for example if I am in a server my ID and the server ID would be inserted into the userGuilds table.
  31. //If I would join another server my ID and the other server ID would also be inserted.
  32.  
  33. SELECT
  34.   playtime.userID AS userID,
  35.   roleAwards.guildID AS guildID,
  36.   roleAwards.roleID AS roleID,
  37.   IF(SUM(TIMESTAMPDIFF(SECOND,startDate, IFNULL(endDate, NOW()))) > roleAwards.time, 1, 0) AS assign
  38.  
  39. FROM
  40.     playtime
  41.  
  42. INNER JOIN roleAwards ON playtime.userID IN (SELECT userID FROM userGuilds WHERE guildID=roleAwards.guildID)
  43.  
  44. WHERE (
  45.     SUBSTRING_INDEX(SUBSTRING_INDEX(roleAwards.game, '|', 1), '|', -1) = playtime.game
  46.     OR SUBSTRING_INDEX(SUBSTRING_INDEX(roleAwards.game, '|', 2), '|', -1) = playtime.game
  47.     OR SUBSTRING_INDEX(SUBSTRING_INDEX(roleAwards.game, '|', 3), '|', -1) = playtime.game
  48. )
  49. AND playtime.startDate > date_sub(NOW(), INTERVAL roleAwards.per SECOND)
  50. AND userID NOT IN (SELECT userID FROM privateUsers)
  51.  
  52. GROUP BY playtime.userID, playtime.game, roleAwards.roleID
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement