FreeKill/server/init.sql
notify f422039b71
在线查看胜率 (#198)
增加了胜率查看功能,长按玩家即可。
- 同步拓展包时若hash一致则跳过
2023-06-16 23:04:31 +08:00

59 lines
1.3 KiB
SQL

-- SPDX-License-Identifier: GPL-3.0-or-later
-- 用户基本信息
CREATE TABLE IF NOT EXISTS userinfo (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name VARCHAR(255),
password CHAR(64),
salt CHAR(8),
avatar VARCHAR(64),
lastLoginIp VARCHAR(64),
banned BOOLEAN
);
CREATE TABLE IF NOT EXISTS banip (
ip VARCHAR(64)
);
-- 胜率相关
CREATE TABLE IF NOT EXISTS winRate (
id INTEGER,
general VARCHAR(20),
mode VARCHAR(16),
win INTEGER,
lose INTEGER,
draw INTEGER,
PRIMARY KEY (id, general, mode)
);
CREATE TABLE IF NOT EXISTS runRate (
id INTEGER,
mode VARCHAR(16),
run INTEGER,
PRIMARY KEY (id, mode)
);
CREATE VIEW IF NOT EXISTS playerWinRate AS
SELECT winRate.id, name, mode,
SUM(win) AS 'win',
SUM(lose) AS 'lose',
SUM(draw) AS 'draw',
SUM(win + lose + draw) AS 'total',
ROUND(SUM(win) * 1.0 / (SUM(win + lose + draw) * 1.0) * 100, 2)
AS 'winRate'
FROM winRate, userinfo
WHERE winRate.id = userinfo.id
GROUP BY winRate.id, mode;
CREATE VIEW IF NOT EXISTS generalWinRate AS
SELECT general, mode,
SUM(win) AS 'win',
SUM(lose) AS 'lose',
SUM(draw) AS 'draw',
SUM(win + lose + draw) AS 'total',
ROUND(SUM(win) * 1.0 / (SUM(win + lose + draw) * 1.0) * 100, 2)
AS 'winRate'
FROM winRate GROUP BY general, mode;