most active time of day based on start and end time

后端 未结 7 1743
悲哀的现实
悲哀的现实 2021-02-08 06:53

I\'m logging statistics of the gamers in my community. For both their online and in-game states I\'m registering when they \"begin\" and when they \"end\". In order to show the

7条回答
  •  广开言路
    2021-02-08 07:38

    I've been overthinking this question myself and based on everyone's answers I think it's obvious to conclude with the following;

    In general it's probably easy to implement some kind of separate table that has the hours of the day and do inner selects from that separate table. Other examples without a separate table have many sub selects, even with four tiers, which makes me believe they will probably not scale. Cron solutions have come to my mind as well, but the question was asked - out of curiosity - to focus on SQL queries and not other solutions.

    In my own case and completely outside the scope of my own question, I believe the best solution is to create a separate table with two fields (hour [Y-m-d H], onlinecount, playingcount) that counts the number of people online at a certain hour and the people playing at a certain hour. When a player stops playing or goes offline we update the count (+1) based on the start and end times. Thus I can easily deduce tables and graphs from this separate table.

    Please, let me know whether you come to the same conclusion. My thanks to @lolo, @rsanchez and @abasterfield. I wish I could split the bounty :)

提交回复
热议问题