select department_id as dashabia from hr.departments;//別名的使用,從hr使用者下查詢departments表,將department_id命名為dashabia並列出
select last_name||' '||job_id as "employees" from employees;//連線符 ||'@' || 中間用引號隔開,可以加字元,但是不可以加'
select ename || q'<'s salary is >'|| sal from scott.emp;
select ename || q'<'s job is >'|| job from scott.emp;//引用操作符alternative quote (q) operator
select distinct department_id from employees;//distinct,去除重複的行
select employee_id , last_name , email ,phone_number , salary ,commission_pct ,department_id from hr.employees where department_id=50;//過濾條件where,一般寫在from table 後面,where子句中不可以使用別名
select employee_id ,first_name ,salary from employees where salary <3000//比較運算子,大於等於之類,太簡單就不說了
select last_name, salary from employees where salary between 2500 and 3500 ;//between,區間值
select employee_id, last_name, salary, manager_id
from employees
where manager_id in (100, 101, 201) ;
select employee_id, last_name, salary, manager_id
from employees
where manager_id =100 or manager_id = 101 or manager_id =201;//in和 or 也很好理解
select first_name from employees where first_name like 's%' ;//模糊查詢,%表示乙個或者多個字元,理解起來就是從employees表中查詢出最初名字開頭為s的姓名,_表示乙個字元
select first_name from employees where first_name like 's_e%' ;//同上,區別在於
_表示乙個字元
select employee_id, last_name, job_id, salary from employees where salary >= 10000 and job_id like '%man%' ;//and ,須保證2邊都為真
select employee_id, last_name, job_id, salary from employees where salary >= 10000 or job_id like '%man%' ;//一邊為真即可
select last_name, job_id, salary
from employees
where job_id = 'sa_rep'
or job_id = 'ad_vp'
and salary > 10000;
select last_name, job_id, salary
from employees
where (job_id = 'sa_rep'
or job_id = 'ad_vp')
and salary > 10000;
//優先級別問題,2者區別,由於在 job_id = 'sa_rep' or job_id = 'ad_vp' and salary > 10000 中,and優先順序大於or,所以先算 job_id = 'ad_vp' and salary > 10000 ,之後再進行( job_id = 'sa_rep' ) or (job_id = 'ad_vp' and salary > 10000) 具體看個人理解,其實道理和1+2*3=? 一樣,所以也就可以使用符號(1+2)*3=? 類似乙個道理,在此查到乙個優先級別表:
運算子級別算術運算子(即『+』,『-』,『*』,『/』)
1連線運算子(即『||』)
2比較運算子(即『>』,『>=』,『<』,『<=』,『<>』)
3is [not] null,[not] like,[not] in
4[not] between-and
5not
6andor
select department_id, last_name
from employees
order by department_id desc;//結果排序,asc:公升序,預設 desc:降序,在order by 列名 之後加desc
DQL語言之基礎查詢(mysql)
語法 select 查詢列表 from 表名 特點 1 查詢列表可以是 表中的字段 常量值 表示式 函式 2 查詢的結果是乙個虛擬的 use course 1 查詢表中的單個字段 select credit from course 2 查詢表中的多個字段 select credit,name cla...
DQL語言之條件查詢(mysql)
語法 select 查詢列表 from 表名where 篩選條件 分類 1 按條件表示式篩選 簡單條件運算子 不等於 也可以 2 按邏輯表示式篩選 邏輯運算子 andor not3 模糊查詢 like between andin isnull isnot null 1 按條件表示式篩選 注意 和 不...
Sql入門 DQL語言
一 select語句 select distinct column1,column2 from table where order by distinct 去除結果的重複行 and 並且 or 或 注意 1 order by子句裡的字段可以縮寫為乙個整數,表示欄位在關鍵字select之後的列表的位置...