I am trying to create a specific sql query, but I have no idea how to implement what I want.My database looks like this:
Col1 Col2 "a" 5 "b" 7 "a" 8 "a" 7 "b" 5 "b" 7 "c" 3 "a" 4 "b" 3 "b" 4 "c" 1
And I want the request to return something like this:
"a" 8 "a" 7 "b" 7 "b" 7
In words: 2 highest values โโof the first x lines.
And only the limit after sorting does not work, because the order refers to the whole result, and not to one "group" of the result. I hope you understand what I'm doing.
This is not very, but ..
SELECT * FROM (SELECT DISTINCT col1, (SELECT col2 FROM tbl WHERE tbl.col1 = a.col1 ORDER BY col2 DESC LIMIT 1) FROM tbl a UNION ALL SELECT DISTINCT col1, (SELECT col2 FROM tbl WHERE tbl.col1 = a.col1 ORDER BY col2 DESC LIMIT 1 offset 1) FROM tbl a) ORDER BY 1,2 DESC;
select tbl.col1, tbl.col2 from tbl inner join (select col2 from tbl order by col2 desc Limit 2) as t1 on t1.col2 = tbl.col2 order by tbl.col1,tbl.col2
, , โโ Hibernate Java, Spring JDBC. . SQL , .
1: , . , . db, , , SQL-, RDBMS, , , - . Hibernate , SQL. , "" - , , , .
Source: https://habr.com/ru/post/1751730/More articles:Idiots Curl Compilation Guide with ssh on Windows - cThe attribute cannot be repeated in C ++ / CLI, but OK in C #? - c #base64 decoder in android at API level 7 - javaActiveMQ: a simple theme-based cluster - apache-camelabout a complete binary tree - binary-treeWhy doesn't the following compile? (includes generics and inheritance in C #) - genericsSelecting only nth-child of a particular element type - jqueryIn MVC Edit Action {HTTP POST} Using UpdateModel vs Request.Form Collection - c #Massaging an array to create a cakephp popup - phpAdvanced iPhone Programming Books - objective-cAll Articles