QSLite Distinct&Qrderby&Groupby

发布时间 2023-12-14 13:50:58作者: 秃头的C#

 distinct关键词专用于消除重复记录

SELECT DISTINCT COLUMN1, COLUMN2,....COLUMNN FROM TABLE_NAME WHERE [CONDITION];

--通过distinct关键字消除重复姓名
select * from staff;

select DISTINCT SNAME FROM STAFF;

 

 

 

order by 子句专用于对一个活多个字段按升序或者降序排序

SELECT COLUMN-LIST

FROM TABLE_NAME

[WHERE CONDITION]

[ORDER BY COLUMN1,COLUMN2,COLUMN3...COLUMNN] [asc|desc]

 

select * from staff ORDER BY ssalary asc;

select * from staff ORDER BY ssalary desc;

 

group by 配合相同数据进行分组

select column-list

from table_name

where [conditions]

group by column1,column2

select *,SUM(ssalary) from staff GROUP BY Spost ORDER BY SNAME;

 

having子句专用于指定条件来过滤数据

Select * from  table_name

where

group by

having

order By;

//统计 按职务分组统计  职务数量大于2个的组别   having 要跟在group by 后面
select
*,sum(ssalary) from staff GROUP BY spost HAVING Count(spost) >2;