Mysql 查詢,刪除


 

//查看表的內容

select * from hpeu_student;

//從第一行查找五行

select * from hpeu_student limit 5;

 

 

//從第一行的下零行查找5行

select * from hpeu_student limit 5 offset 0;

//從第一行的下一行查找5行

select * from hpeu_student limit 5 offset  1;

select * from hpeu_student limit 1,5;

 

//where 后面指定條件 stu_id<4 and stu_name='jim';where通常把小表放在前面,范圍小提高效率

select * from hpeu_student where stu_id = 4;

 

//like的用法:stu_id 含有5的 而且 stu_name含有uc的

select * from hpeu_student where stu_id like '%5%' and stu_name like '%o%';

 

//order by  排序(desc降序 asc升序)  stu_id含有1的按照 stu_name升序排序

select * from hpeu_student where stu_id like '%1%' order by stu_name asc;

 

//group by 分組 兩次篩選后面加 order by 字段 單個必須把name作為主要字段,加入order by可以加多個字段

select * from hpeu_student where stu_id <5 group by stu_name;

select stu_id,stu_name from hpeu_student where stu_id <5 group by stu_name;//報錯count(str_id)就不會報錯 count(str_id) as id 起別名id

 

//having(分組條件) 針對order by 分組之后的再篩選條件,行過濾

select * from hpeu_student where stu_id <5 group by stu_id having stu_id=3;

 

//更新數據 set 后面可以有多個更改,where是條件,沒有就會全部更改

update table set stu_name='Mike'  where stu_id=1;

 

//刪除數據庫(真正的環境中通常都不使用drop)

drop database Test

//刪除表,刪除表結構,必須要從新 新建表

drop table hpeu_student;

//刪除表的全部內容,不刪除表結構,不能與where一起使用,刪除索引,stu_id會從1開始

truncate hpeu_student;

//delete 刪除可以where 加條件刪除,不會刪除索引,stu_id會從后面開始

delete hpeu_student where stu_id>4;

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM