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

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -