I look to made all time soccer table.
I use to table:
- Teams: with info about club: ID, name, team actual name
- FinalTables: with all final table, season by season and level by level
Query is
SELECT
t.team Team,
SUM(CASE WHEN (f.TeamActualName = t.team) THEN 1 ELSE 0 END) Seasons,
SUM(CASE WHEN (f.TeamActualName = t.team) THEN f.utakmica ELSE 0 END) P,
SUM(CASE WHEN (f.TeamActualName = t.team) THEN f.pobjede ELSE 0 END) W,
SUM(CASE WHEN (f.TeamActualName = t.team) THEN f.nerješeni ELSE 0 END) D,
SUM(CASE WHEN (f.TeamActualName = t.team) THEN f.porazi ELSE 0 END) L,
SUM(CASE WHEN (f.TeamActualName = t.team) THEN f.postigao ELSE 0 END) GF,
SUM(CASE WHEN (f.TeamActualName = t.team) THEN f.primio ELSE 0 END) GA,
SUM(CASE WHEN (f.TeamActualName = t.team) THEN f.postigao-f.primio ELSE 0 END) GD,
SUM(CASE WHEN (f.TeamActualName = t.team) THEN f.bodovi ELSE 0 END) Points
FROM
FinalTables AS f,
Teams AS t
WHERE
f.level = 1
GROUP BY
t.id
ORDER BY
Points DESC,
GD DESC,
GF DESC,
Team ASC
This query work great.
I have two problem.
First as in Teams table is listed all club who play during years independent of level, in all time table I receive also lot of club with zero game. For example not all teams play on first level, so all other have zero game. How to avoid it, so receive table only with club who play at least one game on first level, like in example.
Second question is how to add in first column order number. So who have most points are "1.", and this to end, 2, 3, 4.....
All my trying was without success. Some help? :)