gpt4 book ai didi

mysql - SQL查询查看差异值

转载 作者:行者123 更新时间:2023-11-30 23:29:11 24 4
gpt4 key购买 nike

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

最佳答案

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

关于mysql - SQL查询查看差异值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11614062/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com