我有 2 张桌子 游戏和交易 我在 Games 表中使用此公式 sum(EntryFee * Rake/(100 + Rake)*TotalEntry) 来获取值
我在事务表计数(不同的用户ID)中使用此查询来获取值
现在我想将 [sum(EntryFee * Rake/(100 + Rake)*TotalEntry)] 的值除以 [count(distinct UserID)] 的值
例如 sum(EntryFee * Rake/(100 + Rake)*TotalEntry) = 90 且 count(distinct UserID) = 3 那么 90/3 =30 我怎样才能在 MYSQL 中做到这一点
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
CREATE TABLE Games (EntryFee INT, Rake INT, TotalEntry INT); CREATE TABLE Transaction1 (UserID VARCHAR(25)); INSERT INTO Games VALUES (30,16,150),(45,20,100),(15,5,50),(25,20,300),(10,8,270); INSERT INTO Transaction1 VALUES ('Daniel'),('David'),('John'),('Martha'); SELECT Games.EntryFee, Games.Rake, Games.TotalEntry, COUNT(distinct Transaction1.UserID) AS CountUser, (Games.EntryFee * Games.Rake / (100 + Games.Rake) * Games.TotalEntry / COUNT(distinct Transaction1.UserID)) AS Calculate FROM Games JOIN Transaction1 GROUP BY Games.EntryFee, Games.Rake, Games.TotalEntry;结果:
示例查询
SELECT ( SELECT sum(EntryFee * Rake/(100 + Rake)*TotalEntry) FROM Games )/( SELECT count(distinct UserID) FROM Transaction ) MyResult