首页 MySql数据库开发课程 MySQL数据表查询数据命令大全
pay pay

MySQL数据表查询数据命令大全

日期: 五月 8, 2023, 10:07 a.m.
阅读: 169
作者: Python自学网-村长

摘要: MySQL数据表查询数据命令大全

MySQL数据表查询数据命令大全

'''
4.查:
4.1 查的基本语法:
select * from 表名
from是关键字,表示数据来源什么表, *表示在结果集中的所有列,也可以用列名代替某个列,
也可以as为列名起别名,这个别名会显示在结果集中,如果要查询多个列,之间使用逗号分隔
示例:select name, age from student;
别名:select name as a,age from student;

4.2 消除重复行:
在select后面列前面使用distinct可以消除重复的行
select distinct age from student;     比如在性别列中使用distinct,只会显示男女两种可能,类似于集合并集原理

4.3 条件查询:
a.语法:
select * from 表名 where 条件;
b.比较运算符:
等于(=);大于(>);小于(<);大于等于(>=);小于等于(<=);不等于(!= 或者 <>)
select * from student where id>3;
c.逻辑运算符:
and(并且)  or(或)  not(非)
select * from student where id>=3 and sex=0;
d.模糊查询:
like
% :表示多个任意字符
_ :表示一个任意字符
select * from student where name like "t%";    能找出所有的王某某
select * from student where name like "t_";    能找出所有的王某
e.范围查询:
in 表示在一个非连续的范围内
between...and... 表示在一个连续的范围内
select * from student where id in (2,3);   查询id为2,3的学生
select * from student where id between 2 and 5;  查询id在2到5之间的学生,包含2和5
f.空判断:
null与""是不一样的:null是没写,""是写了,但是没有值
判断空:is null
判断非空:is not null
select * from student where sex is null;
g.优先级:
小括号,not,比较运算符,逻辑运算符
and比or优先级高
'''

 

原创视频,版权所有,未经允许,切勿转载,违者必究!
回顶部