MySQL Forums
Forum List  »  Newbie

Re: How do i get the max row from a calculated query?
Posted by: Nick Abelson
Date: January 11, 2021 06:06AM

thanks for helping me but still can't get it to work!
This is what I am doing as I want to get the name and amount of the drink that has been drunk the most:
Select MAX
(totalunits, drinktype.drinkname)
FROM
(SELECT
drinktype.drinkname,
drinkusage.amount,
drinktype.units,
SUM(
DISTINCT drinkusage.amount * drinktype.units
) AS totalunits,
drinkusage.dateofdrink
FROM
drinkusage
INNER JOIN drinktype ON drinktype.drinkid = drinkusage.drinkid
WHERE
drinkusage.userid = '170'
GROUP BY
drinkusage.userid,
drinktype.drinkname,
drinkusage.amount,
drinktype.units,
drinkusage.dateofdrink)
ORDER BY
totalunits
DESC

Options: ReplyQuote




Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.