【Oracle】第二單元 條件和排序

員工ID爲90的

select * from employees e where e.department_id = 90;

員工工資小於4400的

select * from employees e where e.salary < 4400;

between…and在倆個值之間

select * from employees ewhere e.salary between 4400 and 9000;

員工工資在4400到9000之間,包含4400和9000

前面的值小,後面的值大,否則前大後小查詢不到數據

部門ID爲90、60的員工

select * from employees e where e.department_id in (90,60);

員工姓名g結尾的

select * from employees e where e.last_name like '%g';

員工姓名中含有i的

select * from employees e where e.last_name like '%i%';

員工姓名第二位是o的

select * from employees e where e.last_name like '_o%';

員工ID爲空的員工

SELECT * FROM EMPLOYees e where e.department_id is null;

並且 和 and 或者 or

工資一萬以上並且工作名稱含有MAN字符的員工

select * from employees e where e.salary > 10000 and e.job_id like '%MAN%';

工資一萬以上或者工作名稱含有MAN字符的員工

select * from employees e where e.salary > 10000 or e.job_id like '%MAN%';

not 不是 不爲

員工ID不爲空的員工

SELECT * FROM EMPLOYees e where e.department_id is not null;

員工ID不是90、60的員工

SELECT * FROM EMPLOYees e where e.department_id not in (90,60);

escape 轉義

select * from t_char where a like '%#%%' escape '#';

escape後的’#'可以指定任意字符

select * from t_char where a like '%z%%' escape 'z';

order by 默認升序asc 降序desc

部門ID不在90的員工並按照日期升序

SELECT * FROM EMPLOYees e where e.department_id not in (90) order by e.hire_date;

部門ID不在90的員工並按照日期降序

SELECT * FROM EMPLOYees e where e.department_id not in (90) order by e.hire_date desc;

發佈了102 篇原創文章 · 獲贊 18 · 訪問量 4萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章