sql-order-by

Making sense of 'OFFSET/FETCH' in SSMS 2012

点点圈 提交于 2019-12-23 02:05:13
问题 Just installed Microsoft SQL Server Management Studio 2012 today. In familiarizing myself with the pagination feature addition of ORDER BY, I keep running into this error: Msg 102, Level 15, State 1, Line 5 Incorrect syntax near 'OFFSET'. Msg 153, Level 15, State 2, Line 6 Invalid usage of the option NEXT in the FETCH statement. Here is my query: SELECT SingleWomansName, NumberOfCats FROM CatLadies WHERE NumberOfCats > 1 ORDER BY NumberOfCats OFFSET 10 ROWS FETCH NEXT 5 ROWS ONLY I've seen

PostgreSQL: order by column, with specific NON-NULL value LAST

我怕爱的太早我们不能终老 提交于 2019-12-22 14:50:14
问题 When I discovered NULLS LAST , I kinda hoped it could be generalised to 'X LAST' in a CASE statement in the ORDER BY portion of a query. Not so, it would seem. I'm trying to sort a table by two columns (easy), but get the output in a specific order (easy), with one specific value of one column to appear last (got it done... ugly). Let's say that the columns are zone and status (don't blame me for naming a column zone - I didn't name them). status only takes 2 values ('U' and 'S'), whereas

Codeigniter: Order by ascending date

孤街浪徒 提交于 2019-12-22 14:01:08
问题 Hi this is my model code for ordering and getting the data: $this->db->order_by($oBy, "asc"); $query = $this->db->get('books'); Everything is working fine, however in my database i am storing the date as a string, e.g. 01-Jan-2014. Therefore when i order the date it will order it by the day and not year, may i know how can i solve it by sorting by the year, however the data will still display out as 01-Jan-2014 and also it will be displayed in ascending order? Thank you! Error: 回答1: $this->db

Postgres ORDER BY values in IN list using Rails Active Record

橙三吉。 提交于 2019-12-22 12:19:15
问题 I receive a list of UserIds(about 1000 at a time) sorted by 'Income'. I have User records in "my system's database" but the 'Income' column is not there. I want to retrieve the Users from "my system's database" in the Sorted Order as received in the list. I tried doing the following using Active Record expecting that the records would be retrieved in the same order as in the Sorted List but it does not work. //PSEUDO CODE User.all(:conditions => {:id => [SORTED LIST]}) I found an answer to a

MySQL order by rand() grouped by day

ぐ巨炮叔叔 提交于 2019-12-22 11:11:49
问题 Is it possible to get random items inside the same day? For example: +----+---------------------+ | id | md | +----+---------------------+ | 1 | 2010-06-27 11:26:01 | | 2 | 2010-06-27 11:28:20 | | 3 | 2010-06-27 11:29:46 | | 4 | 2010-06-27 11:30:50 | | 5 | 2010-06-27 12:20:56 | | 6 | 2010-06-27 12:27:42 | | 7 | 2010-06-27 15:14:05 | | 8 | 2010-07-06 01:53:33 | | 9 | 2010-07-06 01:52:52 | +----+---------------------+ I want to pick random items inside the same day, but at same time i want it

T-SQL ORDER BY number and letters mixed in string

落爺英雄遲暮 提交于 2019-12-22 10:43:39
问题 I have a range of unique strings which contain numbers and sometimes numbers and a letter, a sample of which reads: 1X 2X 2Y 12X 20 21 The number/s always precede the letter. What is the ORDER BY (T-SQL) clause solution to produce a list which would give me the order as demonstrated above? I tried using LEN( fieldName ), fieldname - which would work but for the 20 and 21. I have tried expressing the strings as an integer but the CAST fails in the conversion process. 回答1: I'm stealing my

MySQL row number

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-22 09:36:33
问题 Say I have a MySQL query, for example: SELECT id, name, surname FROM employees ORDER BY id The result woud be: id name surname 1 Peter Smith 2 John Banjo ... 1384 Will Levenstein While this is an ordered query, I can always assume (as long as I don't change the table) that John Banjo will come out second. Now what if my query was SELECT id, name, surname FROM employees WHERE name = 'John' AND surname = 'Banjo' Could I somehow get what the row number would be in the first query? I'm trying to

how to do orderby with angularJS for string array not object array

折月煮酒 提交于 2019-12-22 08:27:02
问题 i have an string array in angularJS and i want to do some kind of sort for it's element i try this code but it isn't work and i don't know why any one has any idea <div id="cpntainer" data-ng-init="countries = ['Syria','Lebanon','Jordon','Egypt']"> Country Name <br /> <input type="text" data-ng-model="name" /> <br /> <ul> <li data-ng-repeat="country in countries | filter:name | orderBy:country:false "> {{ country }} </li> </ul> </div> 回答1: You can use a function in the orderBy-clause like

Order List by Date and Time (in string format)

你说的曾经没有我的故事 提交于 2019-12-22 04:58:23
问题 Probably what I'm asking is quite simple but I don't seem to be getting this one out. I have a list of elements containing a Date field and a Time field. The Date field is a regular DateTime and the Time field is a string. Time is formatted like HH:mm and ranges in 24h. Ordering my list by Date is simple by doing List.OrderBy(e => e.Date), but I don't seem to be able to later order it by Time so that the order of the records is according the date and the time. I tried this out but it's

how to make sure a record is always at the top in a given resultset in mysql?

这一生的挚爱 提交于 2019-12-22 04:44:34
问题 I have a search query which yields a resultset based on input parameters and the result can be sorted (ASC/DESC) based on different parameters: price, duration etc (with pagination in place and limit of 10 records) I now have a requirement wherein, if I have an id passed in, I'd like the corresponding record to be made to sticky at the top in the given resultset. Lets say we have a package table like this: Package - id - name - mPrice - vPrice - duration // Searching pkg based on Price (in