I am wanting to calculate the difference between the max(value) returned from a database against a row value returned.
Example Data
max(value return) = 400
Returned result should be:
etc
Any ideas how this could achieve?
This is current mySQL statement I am using:
SELECT userName, totalPoints , (totalPoints) AS gap
FROM userTable
WHERE value='1'  
ORDER BY totalPoints DESC
s
Try this below soln.
SELECT A.MaxtotalPoints - A.totalPoints AS GAP
FROM
(
SELECT userName, totalPoints , MAX(totalPoints) MaxtotalPoints
FROM userTable
WHERE value='1'  
) A
ORDER BY GAP;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With