database - More than one maximum value in SQL -


I have to write a question that searches for the maximum value and if there are more items with the same maximum value then Those two will come back. For example, if I have in my database

  item price coffee 2.50 tea 2.50 cola 1.50  

This will give coffee and tea as an answer .

This is usually solved using a window function:

 Select  item, by value (select item, price, dense_rank () value (depending on price) to rnk from the_table) where rnk = 1;  

You have not specified your DBMS, so the above standard (ANSI) is SQL.


Comments

Popular posts from this blog

python - Strange behavior using PyQt4's 'pyqtSlot' decorator before another decorator -

c# - UnhandledExceptionMode.ThrowException for AppDomain.UnhandledException -

c# - Process.Kill() returns access denied -