目錄:
1、數(shù)據(jù)庫的連接、創(chuàng)建
2、對字段的操作:(alter table)
3、對數(shù)據(jù)的操作(插入、修改、刪除)
4、數(shù)據(jù)查詢(select)
5、多表查詢(join on)
6、約束操作
四、數(shù)據(jù)庫查詢大全(select)
1、select 字段名 from 表;
2、In查詢:用于過濾你所需要查詢的內(nèi)容
????????????????select 字段名 from 表名 where 字段名 in(具體內(nèi)容)
????????????
3、范圍查詢between:
????????select 字段名 from 表名 where 字段名 between 數(shù)值1 and 數(shù)值2
????????Eg:查詢當(dāng)字段Salary范圍在3000~5000時,字段Name和Salary的內(nèi)容
????????select Name,Salary from t_emp where Salary between 3000 and 5000
4、模糊查詢like:
????????select 字段名?from 表名?where 字段名?like '模糊條件'
????????模糊條件中”%”與”_”區(qū)別:
????????“%a”:無論字符a前面有多少字符 ”_a”:字符a前面只有一個字符
????????Eg:查詢所有Name以字母C為第二個字符的員工的Name和Salary的內(nèi)容
????????select Name,Salary from t_emp where Name like '_C%'
5、查詢空值/非空:is null/not null
????????select 字段名?from 表名?where 字段名?is null
6、去除重復(fù)結(jié)果:distinct
????????Eg:返回數(shù)據(jù)表中字段Name不重復(fù)的內(nèi)容
????????select distinct?Name from t_emp
7、多條件查詢?and、or:
????????Select 字段名 from 表名 where 表達(dá)式1 and/or 表達(dá)式2
8、分組查詢:查詢的每個分組中首次出現(xiàn)的一條記錄
????????select 字段名 from 表名 group by 待分組的字段名
9、對查詢結(jié)果排序order by(默認(rèn)升序):
????????Select 字段名 from 表名 where 條件 order by 待排序字段名 asc/desc
????????asc:升序(默認(rèn)值可省略) desc:降序
????????Eg:查詢class_id為1的所有信息以score降序的方式顯示結(jié)果 ###
????????select * from tb_score where class_id = 1 order by score desc
10、對查詢結(jié)果數(shù)量進(jìn)行限制limit:
????????Select 字段名 from 表名 limit 偏移值 記錄個數(shù)
????????Eg:按成績降序后查詢班級中第2名到第5名的學(xué)生信息
????????select * from tb_score group by score desc limit??1,4文章來源:http://www.zghlxwxcb.cn/news/detail-401422.html
????????注:偏移值默認(rèn)為0,可不寫,1代表從第一個數(shù)開始取,4代表共記錄4個結(jié)果文章來源地址http://www.zghlxwxcb.cn/news/detail-401422.html
到了這里,關(guān)于SQL數(shù)據(jù)庫的查詢操作大全(select)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!