我正试图解决一个可能很简单的事情,根本就没有专家@mysql
我有第一张桌子'online_players'
mysql> show columns from online_players;
+-------------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------------+--------------+------+-----+---------+-------+
| Agent | varchar(255) | YES | | NULL | |
| Name | varchar(255) | YES | | NULL | |
| Alias | varchar(255) | YES | | NULL | |
| Begin_Date | varchar(100) | YES | | NULL | |
| LastBalanceUpdate | varchar(100) | YES | | NULL | |
| Session_minutes | varchar(100) | YES | | NULL | |
| Balance | varchar(100) | YES | | NULL | |
| Product | varchar(100) | YES | | NULL | |
+-------------------+--------------+------+-----+---------+-------+
8 rows in set (0.04 sec)
每3分钟进行一次droped,重新创建和值插入,它会显示当前正在播放的网站上的玩家...
然后我将此表'players_count':
mysql> show columns from players_count;
+---------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------------+--------------+------+-----+---------+----------------+
| date_count | varchar(50) | YES | | NULL | |
| players_count | varchar(10) | YES | | NULL | |
| product | varchar(10) | YES | | NULL | |
| avg_balance | varchar(100) | YES | | NULL | |
| id | int(11) | NO | PRI | NULL | auto_increment |
+---------------+--------------+------+-----+---------+----------------+
5 rows in set (0.07 sec)
当更新表online_players时,使用特定插入更新表players_count:
USE livefeed;
INSERT INTO players_count(
date_count,players_count,product, avg_balance)
SELECT
now(),
count(Name) as Players,
Product,
Avg(Balance)
FROM
online_players
GROUP BY Product;
当列表1播放器在线时,它可以正常工作:
mysql> select * from players_count
-> ;
+---------------------+---------------+---------+-------------+----+
| date_count | players_count | product | avg_balance | id |
+---------------------+---------------+---------+-------------+----+
| 2016-03-28 17:09:02 | 2 | USD | 0.06 | 1 |
| 2016-03-28 17:12:01 | 1 | USD | 0.12 | 2 |
| 2016-03-28 17:15:00 | 1 | USD | 0.12 | 3 |
| 2016-03-28 17:18:00 | 1 | USD | 0.12 | 4 |
| 2016-03-28 17:21:01 | 1 | USD | 0.12 | 5 |
| 2016-03-28 17:24:00 | 1 | USD | 0.12 | 6 |
+---------------------+---------------+---------+-------------+----+
6 rows in set (0.21 sec)
但是我还想在没有玩家在线的情况下在表player_count中记录一行,即使我的查询高于= 0,例如:
+---------------------+---------------+---------+-------------+----+
| date_count | players_count | product | avg_balance | id |
+---------------------+---------------+---------+-------------+----+
| 2016-03-28 18:01:00 | 0 | USD | 0 | 7 |
| 2016-03-28 18:01:00 | 0 | FUN | 0 | 8 |
我使用表players_count生成“实时”图表,并且每个特定日期需要有0个值。
可能很简单,但我没有在网上找到任何解决方案...... 我是如何修改我的插入/查询来做到这一点的? 谢谢你的帮助