lets say I have a table named “myPlayerInfo” with following rows
'player name' 'number of goals'
'john' '10'
'martin' '20'
'jen' '20'
Q1. How do I write an sql query that prints a new column which is sum of ‘number of goals’ column ?
'player name' 'number of goals' 'Total goals by all players'
'john' '10' '50'
'martin' '20' '50'
'jen' '20' '50'
Q2. How do I write an sql query that prints a new column which is % of goals scored by each player with the total goals column we did in Q1. ?
'player name' 'number of goals' '% goals scored' 'Total goals by all players'
'john' '10' '20' '50'
'martin' '20' '40' '50'
'jen' '20' '40' '50'
You can perform a cartesian join of the total sum of all rows, derived from a subselect: