0,ACID
ACID指數(shù)據(jù)庫(kù)事務(wù)正確執(zhí)行的四個(gè)基本要素的縮寫。包含:原子性(Atomicity)遮婶、一致性(Consistency)、隔離性(Isolation)振诬、持久性(Durability)
1蹭睡, group by,having關(guān)鍵字
** group by分組赶么,having限制組中的元素肩豁。**
舉例子說明:查詢table表查詢每一個(gè)班級(jí)中年齡大于20,性別為男的人數(shù)
select COUNT(*) as '>20歲人數(shù)',classid from Table1 where sex='男' group by classid,age having age>20
需要注意說明:當(dāng)同時(shí)含有where子句辫呻、group by 子句 清钥、having子句及聚集函數(shù)時(shí),執(zhí)行順序如下:
- 執(zhí)行where子句查找符合條件的數(shù)據(jù)放闺;
- 使用group by 子句對(duì)數(shù)據(jù)進(jìn)行分組祟昭;對(duì)group by 子句形成的組運(yùn)行聚集函數(shù)計(jì)算每一組的值;
- 最后用having 子句去掉不符合條件的組怖侦。
having子句相關(guān)的重點(diǎn)篡悟。
--having 子句中的每一個(gè)元素也必須出現(xiàn)在select列表中。有些數(shù)據(jù)庫(kù)例外匾寝,如oracle.
--having子句和where子句都可以用來設(shè)定限制條件以使查詢結(jié)果滿足一定的條件限制搬葬。
--having子句限制的是組,而不是行艳悔。where子句中不能使用聚集函數(shù)急凰,而having子句中可以。
2猜年,like關(guān)鍵字
Table1中有學(xué)生的id抡锈,name,sex乔外;Table2中有id, 學(xué)生的stu_id床三,address;
求姓王的女同學(xué)家的家庭住址袁稽。
select Table1.name, Table1.sex, Table2.address
from Table1 left join Table2 on Table1.id = Table2.stu_id
where name like '王%' and sex = '女'
還可以
select Table1.name, Table1.sex, Table2.address
from Table1 left join Table2 on Table1.id = Table2.stu_id
where left(name,2) ='王' and sex = '女'