I have the following code, bar the possible typo should select 3 columns, the 1st being a rank, opposition and a percentage of losses.
SELECT COUNT(B.F_FACTOR) AS RANK, A.F_OPPOSITION, A.F_FACTOR
FROM
(
SELECT
F_OPPOSITION,
IF(SUM(F_RESULT='L',=1,1,0) AS F_NUM,
IF(SUM(F_RESULT IN ('W','D','L'),=1,1,0) AS F_DENOM,
ROUND(SUM(F_NUM/F_DENOM),2) AS F_FACTOR
FROM $table
GROUP BY F_OPPOSITION
) A,
(
SELECT
F_OPPOSITION,
IF(SUM(F_RESULT='L',=1,=1,=0) AS F_NUM,
IF(SUM(F_RESULT IN ('W','D','L'),=1,=1,=0) AS F_DENOM,
ROUND(SUM(F_NUM/F_DENOM),2) AS F_FACTOR
FROM $table
GROUP BY F_OPPOSITION
) B
WHERE A.F_FACTOR <= B.F_FACTOR
OR (A.F_FACTOR=B.F_FACTOR AND A.F_OPPOSITION=B.F_OPPOSITION)
GROUP BY A.F_OPPOSITION, F_FACTOR
ORDER BY A.F_RANK ASC, A.F_FACTOR DESC, A.F_OPPOSITION DESC;
it is possible that i run this as a cron job to update a table nightly and then do a basic select x,y,z from that table to display this to screen with php, which i will probably do.
But in terms of learning more from a sql standpoint is their a quicker/easier, both in typing and processing, to achieve the same output.
thank you.
added cron job to update table created nightly, processing time is negligible.