标签:
sqlite 的order by 语句是用来对数据进行升序降序排序的,asc 是升序,des 是降序
sqlite> select * from student; id name age ---------- ---------- ---------- 2 bb 12 3 cc 22 1 abcdef 56 4 bb 21 sqlite> select * from student order by name; id name age ---------- ---------- ---------- 1 abcdef 56 2 bb 12 4 bb 21 3 cc 22 sqlite>
sqlite> select * from student order by age desc; id name age ---------- ---------- ---------- 1 abcdef 56 3 cc 22 4 bb 21 2 bb 12 sqlite>
SQLite 的 GROUP BY 子句用于与 SELECT 语句一起使用,来对相同的数据进行分组。
在 SELECT 语句中,GROUP BY 子句放在 WHERE 子句之后,放在 ORDER BY 子句之前。
sqlite> select * from student; id name age ---------- ---------- ---------- 2 bb 12 3 cc 22 1 abcdef 56 4 bb 21 sqlite> select * from student where id>0 group by name order by name; id name age ---------- ---------- ---------- 1 abcdef 56 4 bb 21 3 cc 22 sqlite>
HAVING 子句允许指定条件来过滤将出现在最终结果中的分组结果。
WHERE 子句在所选列上设置条件,而 HAVING 子句则在由 GROUP BY 子句创建的分组上设置条件。
sqlite> select * from student where id >0 group by name having count(name)>1; id name age ---------- ---------- ---------- 4 bb 21 sqlite>
标签:
原文地址:http://www.cnblogs.com/techdreaming/p/5638772.html