運算符 | 符號 | 解釋 | | | | | + | 加法 | | | 減法 | | | 乘法 | | / | 除法,結果是浮點數 | | = | 等於 | | | 大於 | | 或者!= | 不等於 | | = | 大於或者等於 | | DISTINCT後面只有一個列時,表示的是單個欄位查詢結果 ...
運算符
符號 | 解釋 |
---|---|
+ | 加法 |
- | 減法 |
* | 乘法 |
/ | 除法,結果是浮點數 |
= | 等於 |
> | 大於 |
< | 小於 |
<>或者!= | 不等於 |
>= | 大於或者等於 |
<= | 小於或者等於 |
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 '張_';
%
:表示零個或者多個任意字元。_
:表示一個任意字元。\
:表示轉義字元,“%”在字元串中表示字元“%”。