QSLite Distinct&Qrderby&Groupby

 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;

 

posted @   秃头的C#  阅读(15)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示