資料庫中資料的刪選,排序,分組和函式的使用
阿新 • • 發佈:2018-12-09
Select (關鍵字) from(表)where(列)
查詢固定的條件的
Select *from 學生資訊 where 姓名=’女’ and 家庭住址=‘河南’
Select *from 學生資訊 where 家庭住址like‘河南’
排序(對於考試編號為101的成績進行排序)
Select * from 成績資訊 where 考試編號=‘101‘
Order by 分數 asc(升序desc降序)
分組:
Select 考試編號,課程編號,avg(分數) from 成績資訊where 考試編號=‘0801‘
Group by課程編號,考試編號
使用函式
Select max(分數) {avg ,min…..}from 成績資訊where 考試編號=‘0801‘
Having by(只有運用了group by 才能使用having by)
Select * from 成績資訊 where 考試編號=‘101‘
Order by 分數 asc(升序desc降序)
Having avg(分數)>=90
Order by 考試編號
插入資料
Insert into User_id value(‘張’,’465’)
Insert ,,,select語句
Insert 學生資訊
Select* from 學生資訊 where 家庭住址 like ‘河南%’
Top 關鍵字
Select *from 成績資訊 order by 分數 (對於成績資訊表格進行排序)
Select top (6) * from 成績資訊 order by 分數 (對於成績資訊表格進行排序選出前六行)
Select top(6) with ties *from 成績資訊 order by 分數 (選出前六行並且顯示和第六行同樣的值)程式碼片