运算符
| 符号 | 解释 |
|---|---|
| + | 加法 |
| – | 减法 |
| * | 乘法 |
| / | 除法,结果是浮点数 |
| = | 等于 |
| > | 大于 |
| < | 小于 |
| <>或者!= | 不等于 |
| >= | 大于或者等于 |
| <= | 小于或者等于 |
| 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后面有多个列时,表示的是多个字段组合的查询结果去重,即所有字段的值全部一样才去重。
in操作符
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');
between…and
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';
like模糊查询
select * from stuinfo t where t.stuname like '张%'; select * from stuinfo t where t.stuname like '张_';
%:表示零个或者多个任意字符。_:表示一个任意字符。\:表示转义字符,“%”在字符串中表示字符“%”。