一、order by子句
1.order by排序規則
(1)asc,公升序排列,預設取值
(2)desc,降序排列
(3)order by是
select命令的最後乙個子句
select last_name,salary,dept_id
from s_emp
order by salary;
select last_name,salary,dept_id
from s_emp
order by salary asc;
select last_name,salary,dept_id
from s_emp
order by salary desc;
2.order by中
null
值處理(1)公升序中,放最後
(2)降序中,放最前
select last_name,title,commission_pct
from s_emp
order by commission_pct;
3.order by後可跟內容
(1)列名
(2)列的別名
(3)數字:select列表項的位置
select last_name name,salary
from s_emp
order by name;
select last_name,salary*12
from s_emp
order by 2;
4.order by後跟多個列
(1)先按第乙個列排序,內容相同的,再按照第二個列排...
(2)asc、
desc
只修飾乙個列
select last_name,dept_id,salary
from s_emp
order by dept_id,salary desc;
等價select last_name,dept_id,salary
from s_emp
order by dept_id asc,salary desc;
二、where子句
1.限制取出記錄數
(1)where比較中的字串常量嚴格區別大小寫
select last_name,salary,dept_id
from s_emp
where dept_id=42;
select last_name,salary,dept_id
from s_emp
where dept_id=42;
select last_name,salary,dept_id
from s_emp
where last_name='smith';
2.where中的操作符
(1)between...and...:閉區間;先跟小值,再跟大值
select last_name,salary
from s_emp
where salary between 940 and 1100;
select last_name,salary
from s_emp
where salary between 1100 and 940;
(2)in:從給定的列表範圍內匹配值
select last_name,salary,dept_id
from s_emp
where dept_id in(41,43,45);
(3)like:模糊查詢
萬用字元:
%代表0
或多個字元
_代表單一字元
select last_name,salary
from s_emp
where last_name like 'm%';
escape自定義轉義字元,可以讓統配符失去特殊意義,變成普通字元
查出名字以_a開始的?
select last_name,salary
from s_emp
where last_name like '\_a%' escape '\';
(4)is null:空值判斷
空值不能用等號進行比較
*select last_name,salary,title,commission_pct
from s_emp
where commission_pct is null;
(5)多條件查詢
and:多個條件必須同時滿足
or:多個條件選乙個
and的優先順序比or高
select last_name,salary,dept_id
from s_emp
where salary>=1000
and dept_id=44
or dept_id=42;
等價select last_name,salary,dept_id
from s_emp
where (salary>=1000
and dept_id=44)
or dept_id=42;
flask查詢(限制,偏移,排序)
先對所要查詢的表進行排序,然後是所要查詢的內容newslist news.query order by db.desc news.n id filter by n is del false 查詢兩張表,不需要外來鍵result1 jobfair.query join company,jobfair....
SQLAlchemy 查詢(限制,偏移,排序)
先對所要查詢的表進行排序,然後是所要查詢的內容newslist news.query order by db.desc news.n id filter by n is del false 查詢兩張表,不需要外來鍵result1 jobfair.query join company,jobfair....
排序篇之快速排序
快速排序是一種劃分交換排序。它採用了一種分治的策略。1.分治法的基本思想 分治法的基本思想是將原問題分解為若干個規模更小但結構和原問題相似的子問題。遞迴的解決這些子問題,然後將這些子問題的解組合為原問題的解。2.快速排序的基本思想 設待排序的無序區為r low.high 利用分治法可將快速排序的基本...