sql-order-by

Is there a speed difference in ordering by int vs. float?

梦想与她 提交于 2019-12-22 04:16:18
问题 When retrieving entries in a database, is there a difference between storing values as a float or decimal vs. an int when using ORDERBY in a SELECT statement? 回答1: It depends. You didn't specify the RDBMS so I can only speak to SQL Server specifically but data types have different storage costs associated with them. Ints range from 1 to 8 bytes, Decimals are 5-17 and floats are 4 to 8 bytes. The RDBMS will need to read data pages off disk to find your data (worst case) and they can only fit

BLOB data returned in MySQL using AES_DECRYPT with ORDER clause

ⅰ亾dé卋堺 提交于 2019-12-22 00:05:26
问题 I'm creating a system in which users can store messages via PHP with a MySQL database, and I am using the MySQL AES_ENCRYPT function to encrypt the contents of these messages. Here is my posts table: CREATE TABLE IF NOT EXISTS `posts` ( `id` int(11) NOT NULL AUTO_INCREMENT, `user` int(11) DEFAULT NULL, `group` int(11) DEFAULT NULL, `body` varbinary(1000) NOT NULL, `ip` varchar(45) NOT NULL, `date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `replyto` int(11) DEFAULT NULL, PRIMARY KEY (`id`)

Optimize MySql query: Too slow when ordering

眉间皱痕 提交于 2019-12-21 20:57:38
问题 (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

MvcContrib Grid Sorting on complex object

江枫思渺然 提交于 2019-12-21 19:49:47
问题 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

Sorting Nulls last

会有一股神秘感。 提交于 2019-12-21 15:08:56
问题 Want to sort Nulls and Blanks last and have read all the solutions that use either the Coalesce function or the If in the order by column. MY problems is non of these work for me because the column I am sorting on is specified dynamically by the PHP script that creates the query and some of my columns are in two tables in my join. $sortcol="boat"; $sql= "SELECT fleet,b.boat as boat,owner FROM boats as b LEFT JOIN owners as o ON b.boat=o.boat ORDER BY $sortcol"; This works great, I can change

Order LINQ by “string” name

我的未来我决定 提交于 2019-12-21 12:41:47
问题 PROBLEM SOLVED!!! The solution is Linq.Dynamic You do it like this: (from c in Context.AccountCharts where c.Account_FK == account && c.Year_FK == year select c).OrderBy(order); You have to download the System.Linq.Dynamic.dll and include it into your project. Is there a way to order a linq query by the name of a field. like this: from c in Context.AccountCharts where c.Account_FK == account && c.Year_FK == year orderby c["ColName"] select c; Or from c in Context.AccountCharts where c.Account

Order by last 2 characters string

丶灬走出姿态 提交于 2019-12-21 12:26:51
问题 This is the result of my query, but it doesn't order correctly. I want to order by the last 2 characters. The result should be: Fa0/10 below Fa0/9 . Fa0/1 Fa0/10 Fa0/11 Fa0/12 Fa0/2 Fa0/3 Fa0/4 Fa0/5 Fa0/6 Fa0/7 Fa0/8 Fa0/9 Gi0/1 Gi0/2 Null0 Vlan1 My query: SELECT inft.port FROM interfaces AS intf ORDER BY RIGHT(intf.port + 0, 2) Second: sqlfiddle 回答1: Try this: SELECT port FROM interfaces ORDER BY SUBSTRING_INDEX(port, '/', 1), CAST(SUBSTRING_INDEX(port, '/', -1) AS SIGNED) Check the SQL

MYSQL fulltext search order by relevance

拈花ヽ惹草 提交于 2019-12-21 11:01:36
问题 I am trying to get my Full text search to order by relevance. here is my code it works if remove the ORDER BY but doesn't sort by relevance. I have tried this and it actually makes it so it doesnt find any results at all... Any ideas? $query_for_result=mysql_query(" SELECT * FROM Assets WHERE MATCH (`Badge`,`First Name`,`Last Name`,`Service Tag`,`Asset Tag`) AGAINST ('".$query."*' IN BOOLEAN MODE) and `deleted` = '0' ORDER BY relevance DESC"); edit* <input type="text" name="query" /> <input

Get another order after limit

…衆ロ難τιáo~ 提交于 2019-12-21 07:28:27
问题 Imagine I've a table 'users' with two fields: 'age' and 'name'. I want to retrieve the top ten older users and then I want this list of ten sorted by name. Is it possible to do it with MySQL? I've tried this: (doesn't work) SELECT * FROM users order by age, name limit 10 回答1: Use a subselect: SELECT * FROM ( SELECT * FROM users ORDER BY age DESC LIMIT 10 ) AS T1 ORDER BY name The inner select finds the 10 rows you want to return, and the outer select puts them in the correct order. 来源: https:

Update top N values using PostgreSQL

你说的曾经没有我的故事 提交于 2019-12-21 07:19:15
问题 I want to update the top 10 values of a column in table. I have three columns; id , account and accountrank . To get the top 10 values I can use the following: SELECT * FROM accountrecords ORDER BY account DESC LIMIT 10; What I would like to do is to set the value in accountrank to be a series of 1 - 10 , based on the magnitude of account . Is this possible to do in PostgreSQL? 回答1: WITH cte AS ( SELECT id, row_number() OVER (ORDER BY account DESC NULLS LAST) AS rn FROM accountrecords ORDER