sql基礎知識

查詢
select id,name,class,score from class
Select * from class
查不一樣值
select DISTINCT class from class
前5條,mysql不支持top寫法
Select * from class LIMIT 5
第5行起的後面5條數據 offset(第幾條開始)
Select * from class limit 5 offset 5
升序
Select * from class order by score
降序
Select * from class order by score desc
數據過濾
Select * from class where class = 1
Select * from class where class != 1
Select * from class where class BETWEEN 1 and 2
Select * from class where class=1 or class=2
Select * from class where class=2 and name='lm'
通配符 Select * from class where name like '小%'
彙總
Select avg(score) from class
Select count(score) from class
Select max(score) from class
Select min(score) from class
Select sum(score) from class
分組求和
Select sum(score),class from class group by class
錶鏈接
Select name,a.class,info from class a,grade b where a.class=b.class
內連
Select name,a.class,info from class a inner join grade b on a.class =
b.class
A的外鏈接
Select name,a.class,info from class a left outer join grade b on a.class = b.class
結連 UNION all 全部的結連,沒有all的時候至關於多行DISTINCT
select class from class UNION all select class from grade
插入
insert into grade values(null,5,'五班')
insert into grade(class,info)values(5,'五班')
Insert into grade(class,info) select class,info from grade
更新
update class set class=5 where class=4
刪除
delete from class where class=5
建立表
create table demo(id char(40) null, code char(49) not null)
刪除表
drop table demomysql

相關文章
相關標籤/搜索