GROUP BY
代码语言:javascript复制sqlite> select age,sum(salary) from company group by age order by age ;
age sum(salary)
---------- -----------
22 45000.0
23 20000.0
24 30000.0
25 80000.0
27 85000.0
32 20000.0
44 5000.0
45 5000.0
sqlite> select name,sum(salary) from company group by name order by name desc;
name sum(salary)
---------- -----------
Teddy 20000.0
Paul 40000.0
Mark 65000.0
Kim 45000.0
James 20000.0
David 85000.0
Allen 15000.0
sqlite>
HAVING
在最终结果中进行过滤
代码语言:javascript复制sqlite> select name,count(*) from company group by name;
name count(*)
---------- ----------
Allen 1
David 1
James 3
Kim 1
Mark 1
Paul 2
Teddy 1
sqlite> select name,count(*) from company group by name having count(*) < 2;
name count(*)
---------- ----------
Allen 1
David 1
Kim 1
Mark 1
Teddy 1
sqlite>
DISTINCT
去重
代码语言:javascript复制sqlite> select name from company;
name
----------
Paul
Allen
Teddy
Mark
David
Kim
James
Paul
James
James
sqlite> select distinct name from company;
name
----------
Paul
Allen
Teddy
Mark
David
Kim
James
sqlite>