加入收藏 | 设为首页 | 会员中心 | 我要投稿 拼字网 - 核心网 (https://www.hexinwang.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MySql教程 > 正文

怎样查询mysql语句

发布时间:2022-02-18 21:20:23 所属栏目:MySql教程 来源:互联网
导读:这篇文章主要介绍怎么查询mysql语句,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完! 查询mysql语句的方法:查询一张表中的记录时,代码为【select * from 表名 where name=long and age =18】,from后面加表名,where后面是条件,s
      这篇文章主要介绍怎么查询mysql语句,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!
 
      查询mysql语句的方法:查询一张表中的记录时,代码为【select * from 表名 where name='long' and age ='18'】,from后面加表名,where后面是条件,select后面是筛选出的字段。
  
      在mysql中 查询一张表中的记录的时候
 
  书写顺序是: select * from 表名 where name='long' and age ='18';
 
       但是mysql中的执行顺序是
 
  from  后面加表名 确定你是那张表
  where后面是条件 通过条件 来筛选这表的内容
  select后面是 你where筛选出的数据中的 某些字段    * 是所有字段
  # 查询语句执行的结果也是一张表,可以看成虚拟表
  
当我们遇到一个需求时 怎么来分析? 例如
怎么查询mysql语句
 
1.查询id大于等于3小于等于6的数据
 
   给你展示下实际操作  1.先确定 来自哪一张表  from emp   2. 筛选条件 where id >= 3 and id <=6;   3.select  *
 
   select * from emp where id >= 3 and id <= 6;
    select * from emp where id between 3 and 6;  between 等价于id >= 3 and id <= 6
2.查询薪资是20000或者18000或者17000的数据
 
    select id,name from emp where salary = 20000 or salary = 18000 or salary = 17000;
    select id,name from emp where salary in (20000,18000,17000);
3.查询员工姓名中包含o字母的员工姓名和薪资
 
模糊匹配  % 匹配多个任意字符  _ 匹配 一个任意字符
 
select name,salary from emp where name like '%o%';
4.查询员工姓名是由四个字符组成的员工姓名与其薪资 
 
select name, salary from emp where length(name) =4;
select name ,salary from emp where name like "____"
5.查询id小于3或者大于6的数据
 
select * from emp where id<3 or id >6;
select * from emp where id not between 3 and 6;
6.查询薪资不在20000,18000,17000范围的数据
 
select * from emp  where  salary not in (20000,17000,18000);
7.查询岗位描述为空的员工名与岗位名   针对null判断的时候只能用is 不能用=
 
select name ,post from emp where post_comment is null;

(编辑:拼字网 - 核心网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!