sql-order-by

Random order for group of rows in mysql

南楼画角 提交于 2020-01-07 02:50:14
问题 maybe it´s easy but i have no clue how to handle this correctly. I have the following table t1 with this data: ----------------- | id | gr_id | ----------------- | 1 | a | | 2 | a | | 3 | b | | 4 | b | | 5 | c | | 6 | c | | 7 | d | | 8 | d | ----------------- I would like to get randomly gr_ids like this: ----------------- | id | gr_id | ----------------- | 3 | b | | 4 | b | | 5 | c | | 6 | c | | 7 | d | | 8 | d | | 1 | a | | 2 | a | ----------------- Getting ordered gr_ids ascend and descend

How to cast while Sorting?

你说的曾经没有我的故事 提交于 2020-01-07 02:48:10
问题 I have classes Vehicle and class:Car is inherited from class:Vehicle as in below. I have a List which I want to sort using LINQ based on a property of Car class (not of vehicle parent class). class vehicle { public String Name {get; set; } } class Car:Vehicle { public String ModelName {get; set; } } List<Vehicle> vehicleList=new List<Vehicle>(); Car c1 = new Car(); vechicleList.Add(c1); //s note that i am adding **Car** objects Car c2 = new Car(); vechicleList.Add(c2); // added 10 such Car

How to cast while Sorting?

ⅰ亾dé卋堺 提交于 2020-01-07 02:48:07
问题 I have classes Vehicle and class:Car is inherited from class:Vehicle as in below. I have a List which I want to sort using LINQ based on a property of Car class (not of vehicle parent class). class vehicle { public String Name {get; set; } } class Car:Vehicle { public String ModelName {get; set; } } List<Vehicle> vehicleList=new List<Vehicle>(); Car c1 = new Car(); vechicleList.Add(c1); //s note that i am adding **Car** objects Car c2 = new Car(); vechicleList.Add(c2); // added 10 such Car

How can get records after specific id in mysql

时光毁灭记忆、已成空白 提交于 2020-01-06 19:57:07
问题 We have this on mysql: And want return with 2 limit: 1- "SELECT * FROM table ORDER BY point DESC LIMIT 0,2" //return 'google' & 'jsfiddle' 2- "SELECT * FROM table ORDER BY point DESC LIMIT 2,2" //return 'stackoverflow' & 'msn' 3- "INSERT INTO table SET id = 11, name = 'gmail', point = 101 " 4- "SELECT * FROM table ORDER BY point DESC LIMIT 4,2" //return 'msn' & 'emra' in number 4 'msn' is duplicate. I want number 4 return 'emra' & 'facebook'. I can save 'id' and I want query that return

Oracle ordering of results using a mixed varchar column but numeric where clause

a 夏天 提交于 2020-01-06 14:40:27
问题 I have a table with a VARCHAR2 column which contains values that are a mixture of pure-numbers and alpha-numerics. I have a CODE column that contains: 200 215 220 A553 D545 etc. The following query works: select * from TABLE where CLASS = 3 AND (CODE >= 210 and CODE < 220) or CODE = 291) Values that are CLASS 3 are always numeric. But when I add a ORDER BY , it doesn't work: select * from TABLE where CLASS = 3 and (CODE >= 210 and CODE < 220) or CODE = 291) ORDER BY CODE instead I get ORA

Help With Generic LINQ OrderBy Lambda Expression

北城余情 提交于 2020-01-06 09:33:11
问题 Trying to get an OrderBy on an IQueryable to work, not having much luck. Here's my method: public ICollection<T> FindAll<T>(Expression<Func<T,bool>> predicate, Expression<Func<T,int>> orderingKey) where T : Post { return repository .Find() .Where(predicate) .OfType<T>() .OrderBy(orderingKey) .ToPagedList(); } The ordering works if i do this: FindAll(p => p.PostName == "Foo", p => p.PostId); But not if i want to do this: FindAll(p => p.PostName == "Foo", p => p.DateModified); It doesn't work

Help With Generic LINQ OrderBy Lambda Expression

我是研究僧i 提交于 2020-01-06 09:31:28
问题 Trying to get an OrderBy on an IQueryable to work, not having much luck. Here's my method: public ICollection<T> FindAll<T>(Expression<Func<T,bool>> predicate, Expression<Func<T,int>> orderingKey) where T : Post { return repository .Find() .Where(predicate) .OfType<T>() .OrderBy(orderingKey) .ToPagedList(); } The ordering works if i do this: FindAll(p => p.PostName == "Foo", p => p.PostId); But not if i want to do this: FindAll(p => p.PostName == "Foo", p => p.DateModified); It doesn't work

MySQL complex ORDER BY issue

一世执手 提交于 2020-01-06 08:49:27
问题 I have a complicated ordering issue in my query. Raw, Unordered Data: +------+--------+-----------+ | id | job_id | action_id | +------+--------+-----------+ | 1 | 2 | 1 | | 2 | 2 | 2 | | 3 | 1 | 1 | | 4 | 2 | 3 | | 5 | 4 | 1 | | 6 | 1 | 2 | | 7 | 3 | 1 | | 8 | 3 | 2 | | 9 | 4 | 2 | +------+--------+-----------+ Required Ordering: +------+--------+-----------+ | id | job_id | action_id | +------+--------+-----------+ | 7 | 3 | 1 | | 8 | 3 | 2 | | | | | * blank lines added for clarity, | 5 | 4

SQL select order by decimal precision desc

依然范特西╮ 提交于 2020-01-06 08:30:47
问题 I'm interested in finding the most precise decimal values in a database field. I'd like to be able to sort results by descending precision. Is this possible? e.g. 10.1781253 12345.12435 89.763 1.1 2 回答1: You need to order by the substring of the part after any dot. This is going to be a DB specific SQL query and since you didn't mention which one you're using I can't give a detailed SQL example. 来源: https://stackoverflow.com/questions/2448712/sql-select-order-by-decimal-precision-desc

How do I Sort a varchar with numbers and letters without a specific format?

坚强是说给别人听的谎言 提交于 2020-01-06 07:29:38
问题 I have a column named MR which is a varchar. When I run a query with an ORDER BY it doesn't seem to be ordered correctly. select MR, LName, FName from users order by MR Results: MR | LNAME | FNAME ----------+-------+------- 1234-234 | HEN | LO 2343MA2 | SY | JACK MR20001 | LINA | MARY MR200011 | TEST | CASE MR20002 | KO | MIKE Why does MR200011 show before MR20002? Any Idea guys on how I can properly sort this? The format of MR is not fixed. 回答1: You are sorting by string, not by the value of