mysql 更新與查詢(排序 分組 鏈結查詢)

2022-04-29 09:57:10 字數 1293 閱讀 1428

#每一次資料的更新都需要update

update 命令修改 mysql 資料表資料的通用 sql 語法:

update table_name set field1=new-value1,field2=new-value2

[where clause]

當你需要更新資料表中指定行的資料時 where 子句是非常有用的。

mysql 資料表中刪除資料的通用語法:

delete from table_name [where clause]

where 子句從資料表中讀取資料的通用語法:

select field1,field2,...fieldn from table_name1,table_name2...[where condition1 [and [or]]condition2.....

like 子句從資料表中讀取資料的通用語法:

select field1,field2,...fieldn 

from table_name

where field1 like condition1 [and [or]]filed2 ='somevalue'

select* fromrunoob_tblwhererunoob_authorlike'%com';

union 操作符用於連線兩個以上的 select 語句的結果組合到乙個結果集合中。多個 select 語句會刪除重複的資料。

mysql union 操作符語法格式:

select expression1,expression2,...expression_n

from tables

[where conditions]union [all |distinct]select expression1,expression2,...expression_n

from tables

[where conditions];

order by 子句將查詢資料排序後再返回資料:

select field1,field2,...fieldn table_name1,table_name2...order by field1,[field2...][asc [desc]]

select column_name,function(column_name)from table_name

where column_name operatorvalue

group by column_name;

MySQL模糊查詢,排序,分組

模糊查詢時 欄位名 like 乙個或者多個字元,可能有可能沒有 任意乙個字元 select from 表名 where name like 昭 查詢 查詢 中名字含有昭的所有資訊 對查詢到的內容進行排序 select from 表名 order by salary 預設公升序 select from...

mysql實現分組排序查詢

需求 針對於學生的考試成績需要按等級區分 考生,同時把各個等級的人員按照分數的高低排序 如下圖姓名 成績等級 分數序號 趙晴優秀991 李四優秀952 王五良好891 趙六良好872 李天良好853 王小普通781 李思普通752 建立學生成績表 student 姓名name 成績等級 level ...

mysql排序 分組 多表查詢

1.mysql排序 1.1.從大到小排序,不加desc預設情況下是公升序 mariadb fei1 select from student order by age desc id name age 7 lisi 50 4 sean 28 5 zhangshan 26 3 wangqing 25 2...