sql-order-by

Preserving ORDER BY in SELECT INTO

 ̄綄美尐妖づ 提交于 2019-11-27 05:34:11
I have a T-SQL query that takes data from one table and copies it into a new table but only rows meeting a certain condition: SELECT VibeFGEvents.* INTO VibeFGEventsAfterStudyStart FROM VibeFGEvents LEFT OUTER JOIN VibeFGEventsStudyStart ON CHARINDEX(REPLACE(REPLACE(REPLACE(logName, 'MyVibe ', ''), ' new laptop', ''), ' old laptop', ''), excelFilename) > 0 AND VibeFGEventsStudyStart.MIN_TitleInstID <= VibeFGEvents.TitleInstID AND VibeFGEventsStudyStart.MIN_WinInstId <= VibeFGEvents.WndInstID WHERE VibeFGEventsStudyStart.excelFilename IS NOT NULL ORDER BY VibeFGEvents.id The code using the

mysql - order by inside subquery

痞子三分冷 提交于 2019-11-27 05:25:37
I used the following query with MySQL 5.5 (or previous versions) for years without any problems: SELECT t2.Code from (select Country.Code from Country order by Country.Code desc ) AS t2; The order of the result was always descending as I needed. Last week, I just migrated to a new MySQL Version (In fact, I migrated to MariaDB 10.0.14) and now the same query with the same database is not sorted descending anymore. It is sorted ascending (or sorted using the natural order, not sure in fact). So, can somebody could tell me if this is a bug or if this is a change of the behaviour in recent

Properly sorting dotted numbers stored as character in SQL Server

坚强是说给别人听的谎言 提交于 2019-11-27 04:43:26
问题 I have a SQL table that stores a custom item number. Each of these can have a child broken off from it with a separator of . . Each of those can have a child too. An example of what it could be (again, dynamic, don't know what it will be): Item Number 1 1.1 1.1.1 1.1.1.1 1.1.1.1.a 1.1.1.1.b 10 11 2.1 2.10 2.2 2.20 20 3 30 The thing that makes this tough is those numbers are created on the fly and not necessarily in order. You may create 5 numbers (1, 2, 3, 4, 5) and then create a child of 1

What is the default order of a list returned from a Django filter call?

↘锁芯ラ 提交于 2019-11-27 04:32:46
问题 Short Question What is the default order of a list returned from a Django filter call when connected to a PostgreSQL database? Background By my own admission, I had made a poor assumption at the application layer in that the order in which a list is returned will be constant, that is without using 'order_by'. The list of items I was querying is not in alphabetic order or any other deliberate order. It was thought to remain in the same order as which they were added to the database. This

“Order By” using a parameter for the column name

半世苍凉 提交于 2019-11-27 04:27:33
问题 We would like to use a parameter in the "Order By" clause of a query or stored procedure created with the Visual Studio DataSet Designer. Example: FROM TableName WHERE (Forename LIKE '%' + @SearchValue + '%') OR (Surname LIKE '%' + @SearchValue + '%') OR (@SearchValue = 'ALL') ORDER BY @OrderByColumn This error is displayed: Variables are only allowed when ordering by an expression referencing a column name. 回答1: You should be able to do something like this: SELECT * FROM TableName WHERE

Table-Valued function - Order by is ignored in output

喜夏-厌秋 提交于 2019-11-27 04:23:38
We are moving from SQL Server 2008 to SQL Server 2012 and immediately noticed that all our table-valued functions no longer deliver their temp table contents in the correctly sorted order. CODE: INSERT INTO @Customer SELECT Customer_ID, Name, CASE WHEN Expiry_Date < GETDATE() then 1 WHEN Expired = 1 then 1 ELSE 0 END from Customer **order by Name** In SQL Server 2008 this function returns the customers sorted by Name. In SQL Server 2012 it returns the table unsorted. The "order by" is ignored in SQL 2012. Do we have to re-write all the functions to include a sort_id and then sort them when

Sorting string column containing numbers in SQL?

こ雲淡風輕ζ 提交于 2019-11-27 04:23:00
I am trying to sort string column ( containing numbers ). // SELECT `name` FROM `mytable` ORDER BY `name` ASC +----------+ +-- name --+ +----------+ +-- a 1 ---+ +-- a 12 --+ +-- a 2 ---+ +-- a 3 ---+ You see natural sorting algorithm of Mysql is placing a 12 after a 1 ( which is ok for most apps ), But I have unique needs, so I want result should be sorted like this. +----------+ +-- name --+ +----------+ +-- a 1 ---+ +-- a 2 ---+ +-- a 3 ---+ +-- a 12 --+ Is it possible with just SQL , or I have to manipulate result-set at application level? Brad Christie Going on the assumption it's always

SQL ORDER BY date problem

送分小仙女□ 提交于 2019-11-27 04:21:30
Can you please help me in solving this problem. I am trying to order the results of an SQL query by date, but I'm not getting the results I need. The query I'm using is: SELECT date FROM tbemp ORDER BY date ASC Results are: 01/02/2009 03/01/2009 04/06/2009 05/03/2009 06/12/2008 07/02/2009 Results should be: 06/12/2008 03/01/2009 01/02/2009 07/02/2009 I need to select the date in the format above. Your help is much appreciated. It seems that your date column is not of type datetime but varchar. You have to convert it to datetime when sorting: select date from tbemp order by convert(datetime,

Order by multiple columns with Doctrine

给你一囗甜甜゛ 提交于 2019-11-27 04:12:58
问题 I need to order data by two columns (when the rows have different values for column number 1, order by it; otherwise, order by column number 2) I'm using a QueryBuilder to create the query. If I call the orderBy method a second time, it replaces any previously specified orderings. I can pass two columns as the first parameter: ->orderBy('r.firstColumn, r.secondColumn', 'DESC'); But I cannot pass two ordering directions for the second parameter, so when I execute this query the first column is

SQL for ordering by number - 1,2,3,4 etc instead of 1,10,11,12

浪尽此生 提交于 2019-11-27 03:59:10
问题 I’m attempting to order by a number column in my database which has values 1-999 When I use ORDER_BY registration_no ASC I get…. 1 101 102 103 104 105 106 107 108 109 11 110 Etc… So it appears to be ordering by the first digit as oppose to the number. Does anyone know what SQL to use if I want to order this by value? So 1,2,3,4,5,6 etc 回答1: One way to order by positive integers, when they are stored as varchar , is to order by the length first and then the value: order by len(registration_no)