I have a soccer stats table with goal difference that are both positive and negative values. I need to order the goal difference column in order from highest to lowest like e.g
+5 +1 0 -1 -5
I have tried a couple of sql queries but not getting exactly what I need. I can't seem to get the positive and negative values to order properly.
(SELECT stsID, tmName, tmGroup, stsP, stsW, stsD, stsL, stsGF, stsGA, stsGD, stsPoints FROM `stats` WHERE tmGroup='A' AND stsGD='0')
UNION
(SELECT stsID, tmName, tmGroup, stsP, stsW, stsD, stsL, stsGF, stsGA, stsGD, stsPoints FROM `stats` WHERE tmGroup='A' AND stsGD<'0' ORDER BY stsGD DESC, stsPoints DESC, stsGF DESC)
UNION
(SELECT stsID, tmName, tmGroup, stsP, stsW, stsD, stsL, stsGF, stsGA, stsGD, stsPoints FROM `stats` WHERE tmGroup='A' AND stsGD>'0' ORDER BY stsGD ASC, stsPoints DESC, stsGF DESC)
The above gave me:
+5, -5, -1, +1
I also modified it as
SELECT stsID, tmName, tmGroup, stsP, stsW, stsD, stsL, stsGF, stsGA, stsGD, stsPoints FROM stats WHERE tmGroup='A' ORDER BY stsPoints DESC, stsGF DESC, stsGA ASC
this gave me:
+5, +1, -5, -1
I have tried using SIGN() but still not the result I wanted.
SELECT stsID, tmName, tmGroup, stsP, stsW, stsD, stsL, stsGF, stsGA, stsGD, stsPoints FROM stats WHERE tmGroup='A' ORDER BY stsPoints DESC, SIGN(stsGD) DESC, stsGF DESC
output:
+5, +1, -5, -1
I just can't seem to get it right.