sql-order-by

Cassandra error - Order By only supported when partition key is restricted by EQ or IN

梦想与她 提交于 2019-12-04 18:23:15
问题 Here is the table I'm creating, this table contains information about players that played the last mundial cup. CREATE TABLE players ( group text, equipt text, number int, position text, name text, day int, month int, year int, club text, liga text, capitan text, PRIMARY key (name, day, month, year)); When doing the following query : Obtain 5 names from the oldest players that were captain of the selection team Here is my query: SELECT name FROM players WHERE captain='YES' ORDER BY year DESC

Optimize MySql query: Too slow when ordering

*爱你&永不变心* 提交于 2019-12-04 16:54:52
(edited) For more details about the app it self, please, also see: Simple but heavy application consuming a lot of resources. How to Optimize? (The adopted solution was use both joins and fulltext search) I have the following query running up to roughly 500.000 rows in 25 seconds. If I remove the ORDER, it takes 0.5 seconds. Fisrt test Keeping the ORDER and removing all t. and tu. columns, the query takes 7 seconds. Second test If I add or remove an INDEX to the i.created_at field the response time remain the same. QUERY: **EDITED: I'VE NOTICED THAT BOTH GROUP BY AND ORDER BY SLOW DOWN THE

How to use OFFSET and Fetch without Order by in SQL Server

大憨熊 提交于 2019-12-04 16:52:31
问题 I want use OFFSET and Fetch in my SQL server 2012 query.But without any order by.I can not use order by.Because my sort order will be lost. How can I use OFFSET and Fetch without order by and row number and where in my query? My 2 select tables have same structure. INSERT INTO @TempTable [some columns] select [some columns] from table1 order by col1 INSERT INTO @TempTable [same columns] select [some columns] from table2 order by col2 select * from @TempTable OFFSET 20 ROWS FETCH NEXT 50 ROWS

Linq-to-sql orderby thenby

南笙酒味 提交于 2019-12-04 16:14:59
问题 I'm using the following query syntax from table where where orderby orderby Where the first orderby is a date and second orderby is a date. I would assume this would work like orderby thenby but appears to be doing something else. How can I do an orderby thenby using the above syntax without using extension syntax. (Got it) And what does the orderby, orderby do? 回答1: How can I do an orderby thenby using the above syntax without using extension syntax. Use a comma between the fields: orderby a

How can I sort by a table column in varying cases (Oracle)

旧城冷巷雨未停 提交于 2019-12-04 15:37:02
问题 How can I sort a table with a column of varchar2 with characters in varying cases ( UPPER and lower )? For example, when I do an order by of the Name column, I get the following results: ANNIE BOB Daniel annie bob What I want is something like this: ANNIE annie BOB bob Daniel 回答1: Use lower(field) , e.g. select * from tbl order by lower(name) If you need to address special characters for non-english languages then the other answers about NLSSORT may be what you need. If you don't I would try

Doctrine2 Order By before Group By

橙三吉。 提交于 2019-12-04 15:05:47
I am having issues implementing a sub-select solution for ORDERING a resulting dataset before the GROUP BY reduces it. Normally, in SQL you would do a sub-select: SELECT * FROM ( SELECT * FROM a_table order by a_table.timestamp desc ) as table_tmp group by userId However, I am having difficulty implementing this in DQL. Can anyone point me in the right direction please? My query is more complex than this and I assume I JOIN other tables through 'table_tmp' and in the outer SELECT. Thanks. I'm afraid DQL isn't able to handle such a complex query. However Doctrine allows you to write a custom

PHP/MySQL sort inside GROUP

百般思念 提交于 2019-12-04 12:25:15
I have a case where I have to group results from table by brands and then order by some other column. I get my brands from an array. The problem is that when I group by brand this group is sorted by ID (inside group). Is there a way to sort (order by) inside group? Here is my array and mysql query. $laptop_brands = array("Acer", "Apple", "Dell", "HP-Compaq", "IBM-Lenovo", "Sony", "Toshiba", "ASUS", "Fujitsu", "Gateway"); $get_videos_query = "SELECT * FROM users_video WHERE location = 'location_1' AND brand IN ('" . implode("','", $laptop_brands) . '\') GROUP BY brand ORDER BY FIELD (brand,

MySQL order by primary key

烈酒焚心 提交于 2019-12-04 11:47:04
问题 Some SQL servers allow for a generic statement such as ORDER BY PRIMARY KEY . I don't believe this works for MySQL, is there any such workaround that would allow for automated selects across multiple tables or does it require a lookup query to determine the primary key? The workaround I have been working on involves calling a SHOW COLUMNS FROM before running the query. Is there a more efficient way of doing this? Can MySQL determine the primary key of a table during the select process? Update

Order table by proximity to specific latitude/longitude (using MySQL+PHP)

一曲冷凌霜 提交于 2019-12-04 11:26:53
问题 MySQL (table) id | url | lat | lng ---------------------------------- 1 | x | 44.339565 | -101.337891 ---------------------------------- 2 | y | 44.150681 | -101.074219 ---------------------------------- 3 | z | 43.897892 | -100.634766 what I want to do now is order the list according to their proximity to (43.834527,-99.140625). $a = mysql_query("SELECT * FROM table ORDER BY proximity DESC"); while($b = mysql_fetch_assoc($a)) { echo $b['url'].'<br />'; } 回答1: You may be interested in

MvcContrib Grid Sorting on complex object

爷,独闯天下 提交于 2019-12-04 11:13:55
I am trying to work with MvcContrib Grid control. But I cannot seem to get the sorting to work on complex objects that hold other objects. I have setup my controller/classes/Views similar to the OP in this question. Sorting with MVCContrib I have tried to use the SortColumnName to my childobject.property but it gives me an error saying My main object does not have this property. This is my code snippet //POCO class class Issue { public int ID {get; get; } ..... public int priorityId {get; set;} public virtual Priority priority {get; set;} } //Controller code public ViewResult Index(int? pageNo