1.在查詢(xún)結(jié)果中顯示列名:
a.用as關(guān)鍵字:select name as '姓名' from students order by age
b.直接表示:select name '姓名' from students order by age
2.精確查找:
a.用in限定范圍:select * from students where native in ('湖南', '四川')
b.between...and:select * from students where age between 20 and 30
c.“=”:select * from students where name = '李山'
d.like:select * from students where name like '李%' (注意查詢(xún)條件中有“%”,則說(shuō)明是部分匹配,而且還有先后信息在里面,即查找以“李”開(kāi)頭的匹配項(xiàng)。所以若查詢(xún)有“李”的所有對(duì)象,應(yīng)該命令:'%李%';若是第二個(gè)字為李,則應(yīng)為'_李%'或'_李'或'_李_'。)
e.[]匹配檢查符:select * from courses where cno like '[AC]%' (表示或的關(guān)系,與"in(...)"類(lèi)似,而且"[]"可以表示范圍,如:select * from courses where cno like '[A-C]%')
3.對(duì)于時(shí)間類(lèi)型變量的處理
a.smalldatetime:直接按照字符串處理的方式進(jìn)行處理,例如:
select * from students where birth > = '1980-1-1' and birth <= '1980-12-31'
4.集函數(shù)
a.count()求和,如:select count(*) from students (求學(xué)生總?cè)藬?shù))
b.avg(列)求平均,如:select avg(mark) from grades where cno=’B2’
c.max(列)和min(列),求最大與最小
5.分組group
常用于統(tǒng)計(jì)時(shí),如分組查總數(shù):
select gender,count(sno)
from students
group by gender
(查看男女學(xué)生各有多少)
注意:從哪種角度分組就從哪列"group by"
對(duì)于多重分組,只需將分組規(guī)則羅列。比如查詢(xún)各屆各專(zhuān)業(yè)的男女同學(xué)人數(shù) ,那么分組規(guī)則有:屆別(grade)、專(zhuān)業(yè)(mno)和性別(gender),所以有"group by grade, mno, gender"
select grade, mno, gender, count(*)
from students
group by grade, mno, gender
希望與更多計(jì)算機(jī)等級(jí)考試的網(wǎng)友交流,請(qǐng)進(jìn)入計(jì)算機(jī)等級(jí)考試論壇
更多信息請(qǐng)?jiān)L問(wèn):考試吧計(jì)算機(jī)等級(jí)考試欄目
北京 | 天津 | 上海 | 江蘇 | 山東 |
安徽 | 浙江 | 江西 | 福建 | 深圳 |
廣東 | 河北 | 湖南 | 廣西 | 河南 |
海南 | 湖北 | 四川 | 重慶 | 云南 |
貴州 | 西藏 | 新疆 | 陜西 | 山西 |
寧夏 | 甘肅 | 青海 | 遼寧 | 吉林 |
黑龍江 | 內(nèi)蒙古 |