sql 3 關聯式資料庫常用操作

2022-09-20 06:00:17 字數 873 閱讀 1958

#資料抽出

select * from users order by score desc;

select * from users order by team,score desc;

select * from users order by score desc limit 3; (offset偏移量,預設是0)

select * from users order by score desc limit 3 offset 2;

#資料統計(分組,求和,排序,復合)

1. distinct 過濾重複到資料

2. sum 求和函式

3. max/min 最大/最小值

4. group by/h**ing 分組過濾

select distinct team from users;

select sum(score) from users; (max,min)

select * from users where score = (select max(score) from users); 復合查詢,取出表裡得分最多球員的詳細資訊

select team, max(score) from users group by team h**ing max(score) >= 25; h**ing是針對 group by 的過濾條件,查詢team max(score),按照team分組,並且max(score)>=25

select team, max(score) from users group by team h**ing max(score) >= 25 order by max(score),對結果進行排序

常用函式:

資料庫系統概論 關聯式資料庫標準語言SQL(3)

sql的資料插入語句insert通常有兩種形式。一種是插入乙個元組,另一種是插入子查詢的結果。後者可以一次插入多個元組。一 插入元組 插入元組 insert into 表名 屬性列1 屬性列2 values 常量1 常量2 其功能是將新元組插入到指定的表中。如果insert子句沒有指明任何屬性列名,...

讀書筆記 資料庫之關聯式資料庫語言(SQL3)

結構化查詢語言sql structured query language 是基於關係代數與關係演算的語言,是通用的 功能極強的,高度非過程化的關聯式資料庫語言。其資料定義 查詢 操縱 控制的核心功能只用了九個動詞 sql功能 核心動詞 資料查詢 select 資料定義 create alter dr...

資料庫 SQL建立關聯式資料庫

sql語句不區分大小寫 指令show databases 檢視當前資料庫伺服器下有什麼資料庫介面 指令use 庫名 切換當前資料庫 show tables 檢視當前資料庫下有哪些表 介面 當前庫支援的所有字符集 select from character sets 當前庫的預設字符集 show va...