首页 > 数据库技术 > 详细

mysql 查询语句

时间:2021-07-07 10:26:12      阅读:17      评论:0      收藏:0      [点我收藏+]

mysql 查询语句

select * from school;

指定查询列

select id,name from school;

起别名

select id,name as 姓名,sex as 性别,age as 年龄 from student;

去重查询

select distinct sex from student;

where查询过滤

select * from student where sex=‘男‘ and age>18;

比较运算符 < <= > >= !=

select * from student where age<18;
select * from student where age<=20;
select * from student where age>18;
select * from student where age>=18;
select * from student where age!=18;

逻辑运算符 (AND,OR, NOT)

select * from student where age>18 and age<20;
select * from student where age<19 or age>20;
select * from student where `name` not like "王五";

范围运算符 BETWEEN

select * from student where age between 18 and 20;

列表运算符 IN

select * from student where age in(19,20);

非条件(!=)

select * from student where `name` != "王五";

模糊查询 LIKE

通配符: %任意多个字符,_单个字符,[]指定范围的单个字符,[^]不在指定范围的单个字符

select * from student where name like ‘%小%‘;

order by排序语句

asc升序(默认),desc降序

select *from student order by age desc;

group by语句

统计函数

COUNT    求组中项数
SUM    求和
AVG    求平均值
MAX    求最大值
MIN    求最小值
select class_id,avg(age),max(age) from student group by class_id;

操作多表数据

join语句

内连接

select * from student join class on class.id=student.class_id;

左外连接

select * from student left outer join class on class.id=student.class_id;

右外连接

select * from student right outer join class on class.id=student.class_id;

left join语句

select student.id, student.name, class.name as class_name from student left join class on student.class_id=class.id;

mysql 查询语句

原文:https://www.cnblogs.com/hu308830232/p/14979725.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!