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

c# - SignalR: "Protocol error: Unknown transport." when navigating to hub -

class - Kivy: how to instantiate a dynamic classes in python -

python - mayavi mapping a discrete colorbar on a surface -