带条件的查询
单一条件的查询
select salary from users where username = 'aaa';
select username ,salary from users where id = 3;
多条件的查询
查询员工姓名是aaa,或者工资大于2000的员工信息
select * from users where username = 'aaa' or salary >2000;
select * from users where username='aaa' or ( salary>800 and salary <=2000);
select * from users where username='aaa' or salary>800 and salary <=2000;
逻辑运算符的优先级 not ,and ,or的顺序依次递进
比较运算符
select * from users where not (username='aaa');
优先级
带条件的查询:
单一条件查询;
多条件查询;
逻辑运算符有限级:not>and>or
1.单一条件查询
2.多条件查询--用到逻辑运算符
SQL> select * from usres where username='aaa' or salary>200;
select * from usres where username='aaa' or salary>200
*
第 1 行出现错误:
ORA-00942: 表或视图不存在
SQL> select * from users where username='aaa' or salary>200;
编号 用户名 工资
---------- -------------------- ----------
1 aaa 300
2 bbb 400
3 ccc 900
3 cccccc 300
SQL> select * from users where username='aaa' or salary>300;
编号 用户名 工资
---------- -------------------- ----------
1 aaa 300
2 bbb 400
3 ccc 900
SQL> select * from users where username='aaa' or salary > 200 and salary < 2000;
编号 用户名 工资
---------- -------------------- ----------
1 aaa 300
2 bbb 400
3 ccc 900
3 cccccc 300
SQL> select * from users where username='aaa' or (salary > 200 and salary < 2000
);
编号 用户名 工资
---------- -------------------- ----------
1 aaa 300
2 bbb 400
3 ccc 900
3 cccccc 300
SQL> select * from users where not(username='aaa');
编号 用户名 工资
---------- -------------------- ----------
2 bbb 400
3 ccc 900
3 cccccc 300
如图2个语句,结果相同,运算符是有优先级的
逻辑运算符的优先级:按not,and,or的顺序依次递减
逻辑运算符的优先级
比较运算符优先级高于逻辑运算符
逻辑运算符的优先级
比较运算符优先级高于逻辑运算符
带条件的查询
--待条件的查询
1.单一条件查询
SELECT * FROM x1 where id=3;
2.多条件查询
SELECT * FROM X1 WHERE ID=3 AND Xusername='aaa';
SELECT * FROM X1 WHERE ID=3 or (salary>800 and salary<=2000);
SELECT * FROM X1 WHERE NOT (username='aaa');
--先执行的是小括号里面的内容
--逻辑运算符的优先级:按not,and,or 的顺序依次递减
--比较运算符的优先级高于逻辑运算符
带条件的查询
1、单一条件的查询
select salary from users where username='aaa';
select username,salary from users where id=3;
2、多条件查询
查询员工姓名是aaa,或者工资大于300的员工信息
select *from users where username='aaa' or salary>300;
查询名字是aaa,或者工资在800到2000之间的员工信息
select * from users where username='aaa' or (salary>800 and salary<=2000);
select * from users where not (username ='aaa');
1、Oracle数据库中逻辑运算符的优先级:not、and、or。
2、比较运算符的优先级高于逻辑运算符。
3、not运算符使用场景。
1、Oracle数据库中逻辑运算符的优先级:not、and、or。
2、比较运算符的优先级高于逻辑运算符。
3、not运算符使用场景。
比较运算符的优先级高于逻辑运算符
逻辑运算符的优先级别:not and or
select username, salary from users where id=3;带条件查询单一数据
select * from users where username= 'aaa' or (salary >800 and salary <=2000);多条件查询
select * from users where not (username= 'aaa');非逻辑运算符
带条件的查询
单一条件的查询
select salary from users where username='aaa';查询在users表中username为aaa的salary的数值。
查询在users表中id为3的username和salary的数值:select salary,username from users where id='3';
select username from users where salary<'5000';
多条件的查询:
查询username是aaa,或者salary的数值大于2000的信息,
select * from users where salary>2000or username='aaa';
查询username是aaa或者salary的数值在800到2000之间的信息,
select * from users where username='aaa' or (salary>800 and salary<=2000);
在逻辑运算符中not先运行在是and最后是or,比较运算符的优先级高于逻辑运算符。
查询除了username为aaa的其他信息。
select * from users where not(username='aaa');
select * from users where username<>'aaa';
select * from users where username='aaa' or salary>800 and salary<=2000;
运算符的优先级:not>and>or
逻辑运算符的优先级:按not、and、or的顺序依次递减
比较运算符的优先级高于逻辑运算符
NOT逻辑运算:
select ename from emp where not (ename='FORD');
逻辑运算符有and,or,not,也就是逻辑与,逻辑或,逻辑非。
select * from users
where not (username='aaa');
select * from users
where username ='aaa'or(salary>8000 and salary<=2000);小括号内的先执行
select * from users
where username='aaa' or salary>2000;
逻辑运算符的优先级:not>and>or依次递减
比较运算符的优先级高于逻辑运算符
运算符优先级:比较运算符>逻辑运算符(not>and>or)
比较运算符级别高于逻辑运算符
逻辑预算符 not> and >or