sql-order-by

ASP.NET MVC - Model.OrderBy Date has no effect

两盒软妹~` 提交于 2019-12-01 17:02:55
I'm having some difficulties to sort my results by Date. Is there any special method? Because I'm doing this right now: var db = new DB(); var articles = db.Articles; var orderedArticles = articles.OrderBy(a => a.Date); return View(orderedArticles.ToList()); Where Date is a datetime field. And there is no effect for OrderBy(..) or OrderByDescending(..) So I managed to check what is happening. Everytime I add a new Article I'm just using the date on not the time so if I have two articles both for the same day for example: with: var orderedArticles = db.Articles.OrderByDescending(a => a.Date)

ASP.NET MVC - Model.OrderBy Date has no effect

做~自己de王妃 提交于 2019-12-01 16:49:27
问题 I'm having some difficulties to sort my results by Date. Is there any special method? Because I'm doing this right now: var db = new DB(); var articles = db.Articles; var orderedArticles = articles.OrderBy(a => a.Date); return View(orderedArticles.ToList()); Where Date is a datetime field. And there is no effect for OrderBy(..) or OrderByDescending(..) So I managed to check what is happening. Everytime I add a new Article I'm just using the date on not the time so if I have two articles both

Why does Oracle return specific sequence if 'orderby' values are identical?

被刻印的时光 ゝ 提交于 2019-12-01 16:41:21
I'm bewildered by a query in Oracle which is returning in a seemingly random order. SELECT Date, Amount FROM MyTable WHERE Date = '26-OCT-2010' ORDER BY Date This returns the following data: | Date | Amount -------------------------- 1 | 26-OCT-10 | 85 2 | 26-OCT-10 | 9 3 | 26-OCT-10 | 100 I cannot fathom why the database returns the data in this specific order, or why, since the original table would return the data this way. Casting Date to TIMESTAMP confirms that all Date values are the same value - 26-OCT-10 00.00.00.000000000 , therefore, I can rule out that there is a difference in the

How to make Sqlite use an index for ordering on multiple columns in the case of multiple selection from the same table?

若如初见. 提交于 2019-12-01 14:43:09
I have a table with a few hundred thousand lines. (It’s a precomputed table expressing the relation between lemmas of words and other big tables.) I need to do multiple selections to find a combination of different entries, i.e. I have to use “AS” to do select … from ltc as l0, ltc as l1, ltc as l2 … order by ... The speed of the query depends on the sorting: Without sorting, it’s a few milliseconds, with sorting, it can take a few minutes. This is due, as far as I can tell, to the temporary B-Tree that Sqlite builds for sorting, even though I have an index on the sorted column “nr”. I don’t

How to order dynamically created elements based on a custom attribute? [closed]

≡放荡痞女 提交于 2019-12-01 14:33:15
This function seems to work fairly well for sorting divs based on ID: JS var div = $("<div id='3.5'>AA</div>"); div_id_after = Math.floor(parseFloat(div.get(0).id)); $('#'+div_id_after).after(div); HTML <div id='1'>a</div> <div id='2'>b</div> <div id='3'>c</div> <div id='4'>d</div> <div id='5'>e</div> Produces: a b c AA d e But what if I would like to use a custom attribute titled "order"? The ID should not be a number for compatibility issues, but does this same rule apply to custom attributes? If you're trying to sort on a custom data attribute, here's what I've done in the past: html: <ul

Difficulty in writing Stored Proc to fetch data for Jqgrid Pagination

筅森魡賤 提交于 2019-12-01 13:36:31
I am using the following SQL Procedure for getting data to use for pagination in JqGrid in my web Application. ALTER PROCEDURE [dbo].[NewStoredProc] ( @skip int, @pageSize int, @OrderBy Varchar(20), @OrderByDirection Varchar(10) ) AS BEGIN DECLARE @records int; SET NOCOUNT ON; SET @records =(select count(*) from Data where Status='A'); IF @skip <= 0 SELECT TOP (@pageSize) * from Data where Status='A' ORDER BY CASE WHEN @OrderBy='Column1' AND @OrderByDirection='D' THEN Column1 END DESC ,CASE WHEN @OrderBy='Column1' AND @OrderByDirection !='D'THEN Column1 END, CASE WHEN @OrderBy='Column2' AND

SQL query: Can't order by column called “order”?

谁说我不能喝 提交于 2019-12-01 12:39:23
I am pulling a column in an existing script into my template files, and everything is working great. The only problem is, that this script has a column called order , and every row then has a number in that column to show which should be at the top etc. If I set my query to " ORDER BY name " for example, everything works fine, but when I use " ORDER BY order ", then I get a SQL error. Can I not have a column called order ? I can't change column name, because it's part of the script. Is there a way around it? This is the line in my SQL query: SELECT * FROM categories WHERE hide = 0 ORDER BY

Reverse the “natural order” of a MySQL table without ORDER BY?

我的梦境 提交于 2019-12-01 11:18:01
I'm dealing with a legacy database table that has no insertion date column or unique id column, however the natural order of insertion is still valid when examined with a simple SELECT * showing oldest to newest. I'd like like to fetch that data with pagination but reverse the order as if it was ORDER BY date DESC I've thought about wrapping the query, assigning a numeric id to the resulting rows and then do an ORDER BY on the result but wow that seems crazy. Is there a more simple solution I am overlooking? I cannot add columns to the existing table, I have to work with it as is. Thanks for

SQL: GROUP BY records and then get last record from each group? [duplicate]

*爱你&永不变心* 提交于 2019-12-01 11:16:10
Possible Duplicate: SQL Server: Only last entry in GROUP BY I have a table like this: id| name | attendence 1 | Naveed| 1 2 | Naveed| 1 3 | Adil | 1 4 | Adil | 1 I use following query: SELECT * FROM `test` WHERE `attendence`=1 GROUP BY name The result with above query: id| name | attendence 3 | Adil | 1 1 | Naveed | 1 Question: Above result group rows by name but show first row from each group. I want to select last row(by id) from each group. For example: id| name | attendence 2 | Naveed | 1 4 | Adil | 1 How to write query for above result. Thanks SELECT a.* FROM test a WHERE a.attendence = 1

Postgres natural order by

匆匆过客 提交于 2019-12-01 09:30:24
问题 I have a sorting issue in postgres in a column with values such as version. Version is character varying, with values such as the following (un-ordered). 1.2 1.3 1.10.1 1.9 How do I sort in natural order such that when I issue SELECT version FROM TABLE_A ORDER BY version DESC it will give me 1.10.1 1.9 1.3 1.2 instead of 1.9 1.3 1.2 1.10.1 回答1: Postgres allow you to sort by arrays -- which is essentially what the version number represents. Hence, you can use this syntax: order by string_to