2013-12-12 22 views
1

我有一個數據集在sqlite數據庫中有ID和圖像URL。這是因爲如下:
如何使用基於sqlite中的字符串的順序

ID | URL 
1 | http://img.url1.com 
2 |  
3 | http://img.url2.com 
4 | http://img.url3.com 
5 | http://img.url4.com 
6 | 
7 | http://img.url5.com 
8 | 
9 | http://img.url6.com 
10 | 
11 | http://img.url7.com 
12 | http://img.url8.com 
13 | 

我想以這樣的方式相應地解決這與空值的ID出現在底部,並與就近的ID與IMG的URL在頂部獲得出現在最近的值作爲IDS的排序順序如下:

ID | URL 
1 | http://img.url1.com 
3 | http://img.url2.com 
4 | http://img.url3.com 
5 | http://img.url4.com 
7 | http://img.url5.com 
9 | http://img.url6.com 
11 | http://img.url7.com 
12 | http://img.url8.com 
2 |  
6 | 
8 | 
10 | 
13 | 

您能否提供我我需要把什麼樣的查詢?

回答

2
SELECT * FROM T 
ORDER BY (URL IS NULL),id 

SQLFiddle demo

+0

+1就是這樣,但括號是絕對必要的。 –

+0

@LS_dev謝謝。括號不適用於Slqlite,但適用於程序員:) – valex

+0

@valex。非常感謝。 –

相關問題