sql-order-by

Need lambda expression OrderBy with DateTime conversion

与世无争的帅哥 提交于 2019-12-10 17:25:50
问题 I am trying to create a lambda expression (Linq, C# 3.5) that can perform a OrderBy on a value that is of data type String but which actually contains a parse-able DateTime. For example, typical values may be "5/12/2009" , "1/14/2008", etc. The OrderBy clause below works correctly for ordering (as if string data), but I actually want to treat the values as DateTimes, and perform the sort by Date. (The sortColumn would be something like "dateCreated".) List<MyObject> orderedList =

SQL Server order by syntax with Case When and a Constant

大兔子大兔子 提交于 2019-12-10 16:34:21
问题 I'm reading TSQL code someone else wrote and find a somewhat weird syntax. It's doing order by a string. I did some test and the following is the code. Anyone can help me to explain it? Thanks. First Query SELECT * FROM dbo.Products Result: ProductID ProductName SupplierID CategoryID QuantityPerUnit UnitPrice UnitsInStock UnitsOnOrder ReorderLevel Discontinued ----------- ------------------------------- ----------- ----------- -------------------- --------------------- ------------ ----------

How to perform multiple Linq to Entities orderings dynamically

左心房为你撑大大i 提交于 2019-12-10 15:48:24
问题 So my problem is like this; in C# code, I need to perform multiple orderings of an entity set with the help of Linq to Entities, dependent on input parameters. There are three columns to order on, and the order of the ordering columns is itself variable (meaning that for each ordering, I need to look up which column to order on). How can I achieve this? I have some code that should work, but I repeat myself way too much since I haven't been able to parameterize my operations (Linq to Entities

Sort results by search term similarity

爱⌒轻易说出口 提交于 2019-12-10 15:32:58
问题 I have this users collection: { "_id" : ObjectId("501faa18a34feb05890004f2"), "username" : "joanarocha", } { "_id" : ObjectId("501faa19a34feb05890005d3"), "username" : "cristianarodrigues", } { "_id" : ObjectId("501faa19a34feb05890006d8"), "username" : "anarocha", } When I query this: db.users.find({'username': /anaro/i}) results are sorted in natural order (insertion order). I would like to sort them in a similarity search-term order. In this case results should return by this order: { "_id"

MySql - order by monthname

与世无争的帅哥 提交于 2019-12-10 14:33:14
问题 I am trying to order mysql query by month name like: January -- 5 February -- 2 March -- 5 and so on Here is my query, but its not ordering: SELECT leave_balance.balance, MonthName(leave_balance.date_added) AS month FROM leave_balance WHERE leave_balance.staff_id_staff = $iid GROUP BY month, leave_balance.leave_type_id_leave_type HAVING leave_balance.leave_type_id_leave_type = $leaveBalTypID ORDER BY month Kindly tell me where I am doing wrong 回答1: you can specify like ORDER BY FIELD(MONTH,

Is ORDER BY honoured in SQL Server views?

☆樱花仙子☆ 提交于 2019-12-10 14:08:13
问题 In this answer to What are the downsides of using SqlServer Views?, hyprsleepy suggests the ORDER BY clause is not honoured in views in SQL Server. Could anyone explain why this is the case? Edit: Thanks for the answers, but I'm not sure thats the issue. I know you cant add an Order By Clause to a view and I dont have a problem with that, you just add it to the SELECT statement when calling the view, but my impression from the other question was that using an Order By Clause in a SELECT

Mysql Order by last name when full name for column

自作多情 提交于 2019-12-10 13:42:46
问题 I have the following: SELECT * FROM users LEFT JOIN user_info ON users.id=user_info.user_id WHERE ((user_info.tester != 1) OR (user_info.tester is null)) AND id in (SELECT explicituser_id FROM user_login WHERE (created < '2012-12-17' OR created >= date_add('2012-12-17', interval 1 day))) AND id IN (SELECT participte_id FROM roster WHERE roster_id IN (6)) order by substring_index(users.name, ' ', -1) I'm simply trying to sort by the users' last name. However, while it can sort by the first

Which DBMS's allow an order by of an attribute, that is not present in the select clause?

孤人 提交于 2019-12-10 12:59:36
问题 Let's assume I have a table called Cars with 2 columns: CarName , BrandName Now I want to execute this query: select CarName from Cars order by BrandName As you can see, I'd like to return a list, which is sorted by a column, that is not present in the select part of the query. The basic (not optimized) execution sequence of sql commands is: from , where , group by , having , select , order by . The occuring problem is, that BrandName isn't part of what is left after the select command has

Doctrine 2 Order By ASC and Null values in last

孤街醉人 提交于 2019-12-10 12:59:17
问题 I am trying to fetch result which and I need to sort in ascending order. But some values would be null/empty, I need the to be in last while sorting starts from 0 1 2 and then null value. I tried SortableNullsWalker but it did not help. The value I am sorting is not column, its a multiplication of two values which is being sorted, thats why I think SortableNullsWalker did not work. Any help please $dql = 'SELECT (column1 * column2) as distance FROM table) ORDER BY distance ASC '; $dq = $this-

SELECT * FROM people WHERE user_id='$user_id' ORDER BY time GROUP BY surname [closed]

こ雲淡風輕ζ 提交于 2019-12-10 12:27:53
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 8 years ago . I need to pull out all the entries in my database that relate to a certain user_id, order them by the time they were entered into the database (this is php unix time() seconds) and then group them by surname so