SQLite use Order By, but have another delimiter put things at bottom of list
Is there a way to use a SQLite query to get a list of things ordered by 1 delimiter, but have another delimiter grab from the results and put those results at the bottom of the list?
For example, if i have my testTable that looks something like this:
id price date 1 2.00 12/10/2011 2 1.00 09/10/2011 3 3.00 01/01/2012 4 2.00 02/04/2012
If i wanted to sort it by date, i would use:
SELECT * FROM testTable ORDER BY DATE ASC
this would give me:
id price date 2 1.00 09/10/2011 1 2.00 12/10/2011 3 3.00 01/01/2012 4 2.00 02/04/2012
But, what if I want the list sorted by dates, but I want the items that cost 2.00 to be at the bottom? I would want the result to look like:
id price date 2 1.00 09/10/2011 3 3.00 01/01/2012 1 2.00 12/10/2011 4 2.00 02/04/2012
Is there a specific query I can use to achieve this?
Thanks
SELECT *
FROM testTable
ORDER BY CASE WHEN price = 2.00 THEN 1 ELSE 0 END,
DATE
链接地址: http://www.djcxy.com/p/62064.html
上一篇: 删除某些值出现多次SQL的行