我有这个游戏点数表,每个点都在列表中有4列:谁拥有它,在哪个游戏中,在哪个时期,以及游戏的日期。
我无法理解如何计算每位玩家在每场比赛中获得的积分数。我也想把它们按照游戏日和时期(第一和第二)的顺序排列。
到目前为止,我已经尝试过这个:
SELECT
SUM(POINTS)
FROM
(SELECT POINTS, PERIOD
FROM POINTS_17
WHERE NAME = "player")
WHERE
DISTINCT PERIOD ORDER BY DATE, PERIOD.
有关如何执行此操作或从何处开始的任何提示?还是可以的?
答案 0 :(得分:0)
一些意见:
1)使用单引号,而不是双引号。
2)您的问题意味着分组,但要求对无法分组的列进行排序。
3)我已经包含了一些可能回答你问题的疑问。
4)前三个查询显示特定玩家的统计数据。最后三个查询显示每个玩家的统计数据相同。
-- Show a player's stats, ordered by date and period (like you asked). Since there is only one record per date/period, you don't need to SUM the values.
SELECT DATE, PERIOD, POINTS
FROM POINTS_17
WHERE NAME = 'player'
ORDER BY DATE, PERIOD;
-- Get the total and average points per period for a particular player (1st and 2nd period showed separately)
SELECT PERIOD, SUM(POINTS) AS TOTAL_POINTS, AVG(POINTS+0.0) AVERAGE_POINTS, COUNT(*) TOTAL_PERIODS
FROM POINTS_17
WHERE NAME = 'player'
GROUP BY PERIOD
ORDER BY PERIOD;
-- Get the total and average points per period for a particular player
SELECT SUM(POINTS) AS TOTAL_POINTS, AVG(POINTS+0.0) AVERAGE_POINTS, COUNT(*) TOTAL_PERIODS
FROM POINTS_17
WHERE NAME = 'player';
-- Show each player's stats, ordered by date and period.
SELECT NAME, DATE, PERIOD, POINTS
FROM POINTS_17
ORDER BY NAME, DATE, PERIOD;
-- Get the total and average points per period for every player (1st and 2nd period showed separately)
SELECT NAME, PERIOD, SUM(POINTS) AS TOTAL_POINTS, AVG(POINTS+0.0) AVERAGE_POINTS, COUNT(*) TOTAL_PERIODS
FROM POINTS_17
GROUP BY NAME, PERIOD
ORDER BY NAME, PERIOD;
-- Get the total and average points per period for every player
SELECT NAME, SUM(POINTS) AS TOTAL_POINTS, AVG(POINTS+0.0) AVERAGE_POINTS, COUNT(*) TOTAL_PERIODS
FROM POINTS_17
GROUP BY NAME;