日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

mysql level用法_MYSQL使用方法

發布時間:2023/12/2 数据库 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mysql level用法_MYSQL使用方法 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1.查詢一張表:?? ??select * from 表名;

2.查詢指定字段:select 字段1,字段2,字段3….from 表名;

3.where條件查詢:select?字段1,字段2,字段3 frome 表名 where 條件表達式;

例:select * from t_studect where id=1;

select * from t_student where age>22;

4.帶in關鍵字查詢:select?字段1,字段2 frome 表名 where 字段 [not]in(元素1,元素2);

例:select * from t_student where age in (21,23);

select * from t_student where age not in (21,23);

5.帶between and的范圍查詢:select?字段1,字段2 frome 表名 where 字段 [not]between 取值1 and 取值2;

例:select * frome t_student where age between 21 and 29;

select * frome t_student where age not between 21 and 29;

6.帶like的模糊查詢:select?字段1,字段2… frome 表名 where 字段 [not] like ‘字符串’;

“%”代表任意字符;

“_”代表單個字符;

例:select * frome t_student where stuName like ‘張三”;

select * frome t_student where stuName like ‘張三%”;

select * frome t_student where stuName like ‘%張三%”;//含有張三的任意字符

select * frome t_student where stuName like ‘張三_”

7.空值查詢:select?字段1,字段2…frome 表名 where 字段 ?is[not] null;

8.帶and的多條件查詢:

select?字段1,字段2…frome 表名 where 條件表達式1 and 條件表達式2 [and 條件表達式n]

例:select * frome t_student where gradeName=’一年級’ and age=23;

9.帶or的多條件查詢

select?字段1,字段2…frome 表名 where 條件表達式1 or 條件表達式2 [or 條件表達式n]

例:select * frome t_student where gradeName=’一年級’ or age=23;//或者,條件只要滿足一個

10.distinct去重復查詢:select distinct 字段名 from 表名;

11.對查詢結果排序order by:select 字段1,字段2…from 表名 order by 屬性名 [asc|desc]

例:select * frome t_student order by age desc;//降序,從大到小

select * frome t_student order by age asc;//升序,asc默認可以不寫

12.分組查詢group by

group by 屬性名 [having 條件表達式][with rollup]

子查詢

1.帶in關鍵字的子查詢(一個查詢語句的條件可能落在另一個select語句的查詢結果中)

select * from t_book where bookType?in(select id from t_bookType);

select * from t_book where bookType?not?in(select id from t_bookType);

2.帶比較運算符的子查詢(子查詢可以使用比較運算符)

select * from t_book where price>=(select price from t_priceLevel where priceLevel=1);

3.帶exists關鍵字的子查詢(加入子查詢查詢到記錄,則進行外層查詢,否則,不執行外層查詢)

select * from t_book where?exists(select * from t_booktype);

select * from t_book where?not exists(select * from t_booktype);

4.帶any關鍵字的子查詢(any關鍵字表示滿足其中任一條件)

select * from t_book where price>=?any(select price from t_priceLevel);

5.帶all關鍵字的子查詢(all關鍵字表示滿足所有條件)

select * from t_book where price>=?all(select price from t_priceLevel);

合并查詢

1.union

使用union關鍵字是,數據庫系統會將所有的查詢結果合并到一起,然后去掉相同的記錄;

select id from t_book?union?select id from t_bookType;

2.union all

使用union all,不會去除掉重復的記錄;

select id from t_book?union all?select id from t_bookType;

插入操作

插入一條記錄:insert into?t_book?values(null,'我愛我家',20,'張三',1);

插入指定字段:insert into?t_book(bookName,author)?values('我愛我家','張三');

插入多個值:insert into?t_book(bookName,author)?values('我愛我家','張三'),('我家','李四');

更新操作

更新一條數據:update?t_book?set?bookName='java編程思想',price=120 where id=1;

更新幾條數據:?update?t_book?set?bookName where bookName like '%我愛我家%';

刪除操作

刪除一條數據:delete?t_book?where?id=5;

刪除多條數據:delete?t_book?where?bookName='我';

ALTER?TABLE:添加,修改,刪除表的列,約束等表的定義。

總結

以上是生活随笔為你收集整理的mysql level用法_MYSQL使用方法的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。