1

我每天凌晨 4 点拍摄用户登录日志(登录或未登录)的快照,按每个区域和每日用户总数进行分类。但是,我想创建一个 SQL 查询来查看前一天的差异值(可能是百分比),这样我就可以看到哪个区域的用户增加或减少了。我知道我可以对此进行硬编码,但是在相当简单的 SQL 查询中是否有任何优雅的方法可以做到这一点?

4

1 回答 1

0
There are two ways to do this:
First Way:
1. Create a table in your database
    CREATE TABLE user_logs (id int(11) AUTO_INCREMENT, daily_number varchar(1000), current_percentage varchar(30), date datetime)
2. Run the script to get the number of users for that day
    INSERT INTO user_logs (daily_number) VALUES ($daily_value)
3. Create function to compare the latest two DB rows, then insert percentage into (numberOfRows-1)


Second Way:
1. Create a log of the user records in a txt file
2. In the log, append each number seperated by comma
3. Create function to compare the last two values in log and take the average of the two
于 2012-07-23T14:14:58.310 回答