mysql - SQL Querying: Getting the top five tuples based on a value where the value could be the same for some tuples -


As explained in the title, I am trying to get the top five tips based on a price that is In addition to some Tulips, if the value of the fifth tuple is similar to the values ​​of other Tuples in the same table, then I have to display them as well. As an example, suppose I have the following values:

  • person A: value 12
  • person B: value 12
  • person
  • Individual D: Value 15
  • Individual E: Value 16
  • Person F: Value 17
  • Individual G: Value
  • I need to display it:

    • Person g: Value 20 < Li> person F: value 17 <
    • person A: value 16
    • person D: value 15
    • person C: value 12
    • Person B: Price Yes 12
    • Individual A: Value 12

      As a person can see, despite the individuals with the "Top Five" value CG, the person in the table And B also includes because they have the same value as the person C. In addition, anyone can see that the execution of queries like

        select * value work limit 5   

      this table is not produced As it would be, the person would leave A and B. Can anyone provide me some help in this matter? Thank you in advance.

      I think you do not mean MySQL and SQL Server (please edit your tags). If so, you can use a subquarium with in to get the relationship:

        from the select person * where in value (by value Price Select Price Dispatch Limit 5) Value Discount from Order   

      Depending on your desired result, you may need to use different in your subquery Is a bit unclear with your sample data


      Alternatively, you can use join :

        select p. * From the person (choose a different price by ordering the price dissection limit 5) by p.value = p2.value on p2 and p.value desc   

      (I separate < / code> to show the difference with this example.)

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -