kay*_*see 0 sql oracle mysqli teradata
假设我有一个名为"myPlayerInfo"的表,其中包含以下行
'player name' 'number of goals'
'john' '10'
'martin' '20'
'jen' '20'
Run Code Online (Sandbox Code Playgroud)
Q1.如何编写一个打印新列的SQL查询,该列是"目标数"列的总和?
'player name' 'number of goals' 'Total goals by all players'
'john' '10' '50'
'martin' '20' '50'
'jen' '20' '50'
Run Code Online (Sandbox Code Playgroud)
Q2.如何编写一个sql查询来打印一个新列,该列是每个玩家在第一季度完成的总目标列中得分的百分比.?
'player name' 'number of goals' '% goals scored' 'Total goals by all players'
'john' '10' '20' '50'
'martin' '20' '40' '50'
'jen' '20' '40' '50'
Run Code Online (Sandbox Code Playgroud)
你需要使用窗口函数......
select
player_name,
number_of_goals,
(number_of_goals * 100) / SUM(number_of_goals) OVER () AS percent_goals_scored,
SUM([number of goals]) OVER () AS total_goals_by_all_players
from myPlayerInfo
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6448 次 |
| 最近记录: |