【MySQL】课程笔记1

连接两个字符concat
select concat(name1, name2, name3) as `family` from employee;
distinct去除重复数据
select distinct student_id from class;
查询表的结构
show columns from tablename;
ifnull
select first_name, ifnull(last_name, "") from tablename;

条件查询
select field
from tablename
where 查询条件

执行顺序为:
from — where — select

模糊查询

查询名字中包含a的员工信息

select * from employee where name like '%a%'

注意,上面的查询不能写成:

select * from employee where name='%a%'

如果是等号的话,就是查询名字为“%a%”的员工信息,而不是查询名字中包含a的员工信息

查询名字中第三个字符为a的员工信息

select * from employee where name like '__a%'

查询昵称中,第二个字符为_(下划线)的员工信息(即如何描述反义字符):

select * from employee where nick_name like '-\-%';

select * from employee where nick_name like '-$-%' escape '$';

第二种方法中escape '$'的意思是, 符号代替'\\'让 后面的字符保持原始字符,而不是转义字符

发布了390 篇原创文章 · 获赞 27 · 访问量 7万+

猜你喜欢

转载自blog.csdn.net/AXIMI/article/details/104331917