2012年5月26日土曜日

SQLlite:並べ替え

ORDER BY句
カラム名を指定して並べ替え
ResultSet rs = stmt.executeQuery("SELECT * FROM data ORDER BY price ");

結果:
id = 1
date = 5/25
name = りんご
price = 100
id = 3
date = 5/23
name = りんご
price = 101
id = 2
date = 5/24
name = いちご
price = 110


ORDER BY句 昇順
ResultSet rs = stmt.executeQuery("SELECT * FROM data ORDER BY price ASC ");

結果:
id = 1
date = 5/25
name = りんご
price = 100
id = 3
date = 5/23
name = りんご
price = 101
id = 2
date = 5/24
name = いちご
price = 110


ORDER BY句 降順
ResultSet rs = stmt.executeQuery("SELECT * FROM data ORDER BY price DESC ");

結果:
id = 2
date = 5/24
name = いちご
price = 110
id = 3
date = 5/23
name = りんご
price = 101
id = 1
date = 5/25
name = りんご
price = 100

ORDER BY句 複数カラムの指定
ResultSet rs = stmt.executeQuery("SELECT * FROM data ORDER BY price,id ");

指定を省略した場合は昇順
text型とimage型の列は指定できない。


0 件のコメント:

コメントを投稿