数据库查询语句
一.基本查询
1.查询所有数据
select * from table;
2.查询部分字段
select field1,field2 from table;
二.条件查询
`1.单个条件查询
select * from table where field=x;
2.多个条件查询
select * from table where field1=x and field2=y;
三.模糊查询
select * from table where field like "%x%";
四.范围查询
1.in/not in
select * from table where field in (x,y);
2.between and
select * from table where field between a and b;
3.大于小于
select * from table where field<a and field>b;
五.聚合函数
1.聚合函数
select count(*),max(a),min(a),avg(a) from table;
2.分组
select count(*) from table group by field1;
3.筛选
select count(*) from table having field>a;
4.聚合函数组合使用
select count(*) from table where field1>a group by field2 having count(field3)>b;
六.左右连接
1.左连接
select * from table1 left join table2 on table1.a=table2.b;
2.右连接
select * from table1 right join table2 on table1.a=table.b;
3.内连接
slect * from table1 inner join table2 on table1.a=table2.b;
七.排序
1.升序
select * from table order by field asc;
2.降序
select * from table order by field desc;
八.分页
select * from table limit 1,3; #从第一行开始的三行
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本