[学习笔记] Oracle运算符、连接符、结果去重、范围查询、模糊查询
阅读原文时间:2023年07月09日阅读:2

符号

解释

+

加法

-

减法

*

乘法

/

除法,结果是浮点数

=

等于

>

大于

<

小于

<>或者!=

不等于

>=

大于或者等于

<=

小于或者等于

AND

逻辑与

OR

逻辑或

NOT

逻辑非

select '姓名:' || c.stuname || ', 课程:' || b.coursename || ', 成绩:' || a.score || '分。' as sxcj
   from score a, course b, stuinfo c
   where a.courseid = b.courseid
   and a.stuid = c.stuid;


SELECT DISTINCT 列1,列2,列3... from 表名;

select distinct b.coursename, t.score
   from score t, course b
   where t.courseid = b.courseid
   and t.courseid = 'R20180101';

DISTINCT后面只有一个列时,表示的是单个字段查询结果去重

DISTINCT后面有多个列时,表示的是多个字段组合的查询结果去重,即所有字段的值全部一样才去重。

select t.stuid,
       t.courseid,
       t.score,
       b.stuname,
       b.sex,
       b.age,
       b.classno,
       b.grade
  from score t, stuinfo b
 where t.stuid = b.stuid
   and t.courseid = 'R20180101'
   and t.score in ('85','89','79');


select t.stuid,
       t.courseid,
       t.score,
       b.stuname,
       b.sex,
       b.age,
       b.classno,
       b.grade
  from score t, stuinfo b
 where t.stuid = b.stuid
   and t.courseid = 'R20180101'
   and t.score between '70' and '95';


select * from STUINFO t where t.stuname like '张%';
select * from STUINFO t where t.stuname like '张_';
  • %:表示零个或者多个任意字符。
  • _:表示一个任意字符。
  • \:表示转义字符,“%”在字符串中表示字符“%”。