数据查询(sql运算符)

数据查询(sql运算符),第1张

数据查询(sql运算符)
  1. 数据的导入
    我们的数据库可以运行已经写好的sql文件,将其中的数据添加到数据库或表中。
    Linux下使用命令运行

    source /home/emp.sql;
    

    Windows下使用命令运行

    source d:/emp.sql;
    

    如果运行后查询内容是乱码,运行set names gbk;

  2. 判断null

    使用is null 和 is not null判断数据是否为空

    	查询没有上级领导的运功信息
    	select * from emp where mgr is null;
    
    	查询有上级领导的员工姓名
    	select ename from emp where mgr is not null;
    
  3. 关系运算符
    sql 的运算符: != 和 <> 都是不等于

    	select ename, sal from emp where sal<= 3000;
    
    	查询工作不是程序员的员工姓名和工作
    	select ename, job from emp where job!='程序员';
    	select ename, job from emp where job<>'程序员';
    
  4. 逻辑运算符
    sql中的逻辑运算符and 和 or 类似 java中的 && 和 ||

    查询1号部门工资高于2000的员工信息。
    select * from emp where deptno=1 and sal > 2000;
    
    查询工作是人事或工资大于3000的员工姓名,工资,工作
    select ename,sal,job from emp where job='人事' or sal>3000;
    
    
  5. between关键字

查询x和y之间 包含x和y
查询工资在2000到3000之间的员工姓名和工资。
select ename,sal from emp where sal >= 2000 and sal <= 3000;
select ename,sal from emp where sal between 2000 and 3000;
  1. in关键字
    工资为3000,1500, 5000的员工姓名和工资
select ename,sal from emp where sal=3000 or sal=1500 or sal=5000;

select ename,sal from emp where sal in(3000,1500,5000);

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5684285.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存