php - Selecting Max Value and Key mySQL -
i know simple fix, cannot mind wrapped around it.
i have table factproductsales has sales transactions. have find product has highest sales. have give productid , amount.
here have:
select productid, max(salestotalcost) factproductsales
it gives me right amount, gives me wrong productid. should 5 instead gives me 1. think mistake making obvious one. help
select productid, max(salestotalcost) max_cost factproductsales group productid order max_cost desc limit 5;
use group by, order , limit 5 find max saletotalcost
Comments
Post a Comment