中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當(dāng)前位置: 首頁 > news >正文

登錄網(wǎng)站顯示系統(tǒng)維護(hù)怎么做網(wǎng)站子域名查詢

登錄網(wǎng)站顯示系統(tǒng)維護(hù)怎么做,網(wǎng)站子域名查詢,網(wǎng)頁制作簡易代碼,小城建設(shè)的網(wǎng)站文章目錄 1. 注釋2. 新增(Create)3. 查詢(Retrieve)3.1 全列查詢3.2 指定列查詢3.3 查詢字段為表達(dá)式3.4 別名3.5 去重: distinct3.6 排序: order by3.7條件查詢3.8 分頁查詢 4. 修改 (update)5. 刪除(delete)6. 內(nèi)容重點(diǎn)總結(jié) 1. 注釋 注釋:在SQL中可以使用“–空格…

文章目錄

  • 1. 注釋
  • 2. 新增(Create)
    • 3. 查詢(Retrieve)
    • 3.1 全列查詢
    • 3.2 指定列查詢
    • 3.3 查詢字段為表達(dá)式
    • 3.4 別名
    • 3.5 去重: distinct
    • 3.6 排序: order by
    • 3.7條件查詢
    • 3.8 分頁查詢
  • 4. 修改 (update)
  • 5. 刪除(delete)
  • 6. 內(nèi)容重點(diǎn)總結(jié)

1. 注釋

注釋:在SQL中可以使用“–空格+描述”來表示注釋說明
CRUD 即增加(Create)、查詢(Retrieve)、更新(Update)、刪除(Delete)四個(gè)單詞的首字母縮寫。

2. 新增(Create)

語法insert into + 表名 + values (字段1, 字段2, ...), (字段1, 字段2, ...), ...其中字段1, 字段2, …對應(yīng)了創(chuàng)建表時(shí)對應(yīng)的位置. 如果要使插入的數(shù)據(jù)與相應(yīng)的列相對應(yīng), 則可以insert into + 表名 + (列名1, 列名2, ...) values (字段1, 字段2, ...), (字段1, 字段2, ...), ...如果插入的數(shù)據(jù)量比設(shè)計(jì)表時(shí)數(shù)據(jù)量少就會給少的位置賦予null值. 具體操作舉例如下:
我們先創(chuàng)建一張Student表, 具體設(shè)定如下
在這里插入圖片描述
示例1 直接多行全列插入數(shù)據(jù)insert into student values(1,'張三'),(2, '李四');
在這里插入圖片描述
示例2 多行指定列插入insert into student(name) values('王五'), ('趙六');
在這里插入圖片描述

3. 查詢(Retrieve)

語法

select[distinct] {* | {column [, column] ...} --字段[from table_name]--表名[where...]--查詢條件[order by column [asc| desc], ...]--排序limit...--分表查詢

著非常復(fù)雜, 下面我們來一步一步去拆分講解.

---我們先創(chuàng)建一個(gè)考試成績表, 并插入適當(dāng)?shù)臄?shù)據(jù), 方便我們接下來的分析
create table exam(id int, name varchar(20), chinese decimal(3, 1), math decimal(3, 1), english decimal(3, 1));insert into exam values
(1,'唐三藏', 67, 98, 56), 
(2,'孫悟空', 87.5, 78, 77), 
(3,'豬悟能', 88, 98.5, 90), 
(4,'曹孟德', 82, 84, 67),
(5,'劉玄德', 55.5, 85, 45),
(6,'孫權(quán)', 70, 73, 78.5),
(7,'宋公明', 75, 65, 30);

3.1 全列查詢

-- 通常情況下不建議使用 * 進(jìn)行全列查詢
-- 1. 查詢的列越多,意味著需要傳輸?shù)臄?shù)據(jù)量越大;
-- 2. 可能會影響到索引的使用。
mysql> select * from exam;

在這里插入圖片描述

3.2 指定列查詢

-- 指定列的順序不需要按定義表的順序來
select id, name, english from exam;

在這里插入圖片描述

3.3 查詢字段為表達(dá)式

-- 表達(dá)式不包含字段
select id, name, 10 from exam;
-- 表達(dá)式包含一個(gè)字段
select id, name, english+10 from exam;
-- 表達(dá)式包含多個(gè)字段
select id, name, chinese+math+english from exam;

在這里插入圖片描述

3.4 別名

為查詢結(jié)果中的列指定別名,表示返回的結(jié)果集中,以別名作為該列的名稱,語法:

SELECT column [AS] alias_name [...] FROM table_name;
-- 結(jié)果集中,表頭的列名=別名
select id, name, chinese+math+english as 總分 from exam;

在這里插入圖片描述

3.5 去重: distinct

--通過查詢得知98分重復(fù)了
select math from exam;
+------+
| math |
+------+
| 98.0 |
| 78.0 |
| 98.0 |
| 84.0 |
| 85.0 |
| 73.0 |
| 65.0 |
+------+
--去重查詢
select distinct math from exam;
+------+
| math |
+------+
| 98.0 |
| 78.0 |
| 84.0 |
| 85.0 |
| 73.0 |
| 65.0 |
+------+

3.6 排序: order by

語法

-- ASC 為升序(從小到大)
-- DESC 為降序(從大到小)
-- 默認(rèn)為 ASC
SELECT ... FROM table_name [WHERE ...] ORDER BY column [ASC|DESC], [...];

1.沒有 order by 子句的查詢,返回的順序是未定義的,永遠(yuǎn)不要依賴這個(gè)順序
2.null數(shù)據(jù)排序,視為比任何值都小,升序出現(xiàn)在最上面,降序出現(xiàn)在最下面

--不加desc, 默認(rèn)升序排序
select id, name, chinese+math+english as 總分 from exam order by 總分;
+------+-----------+--------+
| id   | name      | 總分   |
+------+-----------+--------+
|    7 | 宋公明    |  170.0 |
|    5 | 劉玄德    |  185.5 |
|    1 | 唐三藏    |  221.0 |
|    6 | 孫權(quán)      |  221.5 |
|    4 | 曹孟德    |  233.0 |
|    2 | 孫悟空    |  242.5 |
|    3 | 豬悟能    |  276.0 |
+------+-----------+--------+
--加desc, 降序排序
select id, name, chinese+math+english as 總分 from exam order by 總分 desc;
+------+-----------+--------+
| id   | name      | 總分   |
+------+-----------+--------+
|    3 | 豬悟能    |  276.0 |
|    2 | 孫悟空    |  242.5 |
|    4 | 曹孟德    |  233.0 |
|    6 | 孫權(quán)      |  221.5 |
|    1 | 唐三藏    |  221.0 |
|    5 | 劉玄德    |  185.5 |
|    7 | 宋公明    |  170.0 |
+------+-----------+--------+
--多列排序, 分先后
select id, name, chinese, math from exam order by chinese desc, math;
+------+-----------+---------+------+
| id   | name      | chinese | math |
+------+-----------+---------+------+
|    3 | 豬悟能    |    88.0 | 98.0 |
|    2 | 孫悟空    |    87.5 | 78.0 |
|    4 | 曹孟德    |    82.0 | 84.0 |
|    7 | 宋公明    |    75.0 | 65.0 |
|    6 | 孫權(quán)      |    70.0 | 73.0 |
|    1 | 唐三藏    |    67.0 | 98.0 |
|    5 | 劉玄德    |    55.5 | 85.0 |
+------+-----------+---------+------+
--先對Chinese進(jìn)行降序排序, 在不影響原來排序結(jié)果的基礎(chǔ)上再對math進(jìn)行升序排序

3.7條件查詢

比較運(yùn)算符:
在這里插入圖片描述
邏輯運(yùn)算符:
在這里插入圖片描述
注意:
1.WHERE條件可以使用表達(dá)式,但不能使用別名。
2.AND的優(yōu)先級高于OR,在同時(shí)使用時(shí),需要使用小括號()包裹優(yōu)先執(zhí)行的部分
示例:

  • 基本查詢
-- 查詢英語不及格的同學(xué)及英語成績 ( < 60 )
select name, english from exam where english < 60;
+-----------+---------+
| name      | english |
+-----------+---------+
| 唐三藏    |    56.0 |
| 劉玄德    |    45.0 |
| 宋公明    |    30.0 |
+-----------+---------+
-- 查詢語文成績好于英語成績的同學(xué)
select name, chinese, english from exam where chinese > english;
+-----------+---------+---------+
| name      | chinese | english |
+-----------+---------+---------+
| 唐三藏    |    67.0 |    56.0 |
| 孫悟空    |    87.5 |    77.0 |
| 曹孟德    |    82.0 |    67.0 |
| 劉玄德    |    55.5 |    45.0 |
| 宋公明    |    75.0 |    30.0 |
+-----------+---------+---------+
-- 查詢總分在 200 分以下的同學(xué)
select name, chinese + math + english as 總分 from exam where chinese + math + english < 200;
+-----------+--------+
| name      | 總分   |
+-----------+--------+
| 劉玄德    |  185.5 |
| 宋公明    |  170.0 |
+-----------+--------+
  • and 與 or
-- 查詢語文成績大于80分,且英語成績大于80分的同學(xué)
select * from exam where chinese > 80 and math > 80;
+------+-----------+---------+------+---------+
| id   | name      | chinese | math | english |
+------+-----------+---------+------+---------+
|    3 | 豬悟能    |    88.0 | 98.0 |    90.0 |
|    4 | 曹孟德    |    82.0 | 84.0 |    67.0 |
+------+-----------+---------+------+---------+
-- 查詢語文成績大于80分,或英語成績大于80分的同學(xué)
select * from exam where chinese > 80 or math > 80;
+------+-----------+---------+------+---------+
| id   | name      | chinese | math | english |
+------+-----------+---------+------+---------+
|    1 | 唐三藏    |    67.0 | 98.0 |    56.0 |
|    2 | 孫悟空    |    87.5 | 78.0 |    77.0 |
|    3 | 豬悟能    |    88.0 | 98.0 |    90.0 |
|    4 | 曹孟德    |    82.0 | 84.0 |    67.0 |
|    5 | 劉玄德    |    55.5 | 85.0 |    45.0 |
+------+-----------+---------+------+---------+
--and的優(yōu)先級比or高
  • 范圍查詢
--1. between...and...-- 查詢語文成績在 [80, 90] 分的同學(xué)及語文成績
select name, chinese from exam where chinese between 80 and 90;
-- 使用 AND 也可以實(shí)現(xiàn)
select name, chinese from exam where chinese >= 80 and chinese <= 90;
+-----------+---------+
| name      | chinese |
+-----------+---------+
| 孫悟空    |    87.5 |
| 豬悟能    |    88.0 |
| 曹孟德    |    82.0 |
+-----------+---------+--2. in-- 查詢數(shù)學(xué)成績是 58 或者 59 或者 98 或者 99 分的同學(xué)及數(shù)學(xué)成績
select name, math from exam where math in (58, 59, 98, 99);
-- 使用 OR 也可以實(shí)現(xiàn)
select name, math from exam where math = 58 or math = 59 or math = 98 or math = 99;
+-----------+------+
| name      | math |
+-----------+------+
| 唐三藏    | 98.0 |
| 豬悟能    | 98.0 |
+-----------+------+
  • 模糊查詢: like
-- % 匹配任意多個(gè)(包括 0 個(gè))字符
select name from exam where name like '孫%';
+-----------+
| name      |
+-----------+
| 孫悟空    |
| 孫權(quán)      |
+-----------+
-- _ 匹配嚴(yán)格的一個(gè)任意字符
select name from exam where name like '孫_';
+--------+
| name   |
+--------+
| 孫權(quán)   |
+--------+
  • NULL的查詢: is [not] null
-- 查詢 qq_mail 已知的同學(xué)姓名
select name, qq_mail from student where qq_mail is not null;-- 查詢 qq_mail 未知的同學(xué)姓名
select name, qq_mail from student where qq_mail is null;

3.8 分頁查詢

語法

-- 起始下標(biāo)為 0
-- 從 0 開始,篩選 n 條結(jié)果
SELECT ... FROM table_name [WHERE ...] [ORDER BY ...] LIMIT n;
-- 從 s 開始,篩選 n 條結(jié)果
SELECT ... FROM table_name [WHERE ...] [ORDER BY ...] LIMIT s, n;
-- 從 s 開始,篩選 n 條結(jié)果,比第二種用法更明確,建議使用
SELECT ... FROM table_name [WHERE ...] [ORDER BY ...] LIMIT n OFFSET s;

分頁示例

-- 第 1 頁
select * from exam order by id limit 3 offset 0;
+------+-----------+---------+------+---------+
| id   | name      | chinese | math | english |
+------+-----------+---------+------+---------+
|    1 | 唐三藏    |    67.0 | 98.0 |    56.0 |
|    2 | 孫悟空    |    87.5 | 78.0 |    77.0 |
|    3 | 豬悟能    |    88.0 | 98.0 |    90.0 |
+------+-----------+---------+------+---------+
-- 第 2 頁
select * from exam order by id limit 3 offset 3;
+------+-----------+---------+------+---------+
| id   | name      | chinese | math | english |
+------+-----------+---------+------+---------+
|    4 | 曹孟德    |    82.0 | 84.0 |    67.0 |
|    5 | 劉玄德    |    55.5 | 85.0 |    45.0 |
|    6 | 孫權(quán)      |    70.0 | 73.0 |    78.5 |
+------+-----------+---------+------+---------+
-- 第 3 頁,如果結(jié)果不足 3 個(gè),不會有影響
select * from exam order by id limit 3 offset 6;
+------+-----------+---------+------+---------+
| id   | name      | chinese | math | english |
+------+-----------+---------+------+---------+
|    7 | 宋公明    |    75.0 | 65.0 |    30.0 |
+------+-----------+---------+------+---------+

4. 修改 (update)

語法

UPDATE table_name SET column = expr [, column = expr ...][WHERE ...] [ORDER BY ...] [LIMIT ...]

案例

-- 將孫悟空同學(xué)的數(shù)學(xué)成績變更為 80 分
update exam set math = 80 where name = '孫悟空';-- 將曹孟德同學(xué)的數(shù)學(xué)成績變更為 60 分,語文成績變更為 70 分
update exam set math = 60, chinese = 70 where name = '曹孟德';-- 將總成績倒數(shù)前三的 3 位同學(xué)的數(shù)學(xué)成績加上 30 分
update exam set math = math + 30 order by chinese + math + english limit 3;-- 將所有同學(xué)的語文成績更新為原來的 2 倍
update exam set chinese = chinese * 2;

5. 刪除(delete)

語法

DELETE FROM  table_name [WHERE ...] [ORDER BY ...] [LIMIT ...]

案例

-- 刪除孫悟空同學(xué)的考試成績
delete from exam where name = '孫悟空';-- 刪除整表數(shù)據(jù)
delete from exam;

6. 內(nèi)容重點(diǎn)總結(jié)

  • 新增
-- 單行插入
insert into(字段1, ..., 字段N) values (value1, ..., value N);
-- 多行插入
insert into(字段1, ..., 字段N) values
(value1, ...),
(value2, ...),
(value3, ...);
  • 查詢
-- 全列查詢
select * from-- 指定列查詢
select 字段1,字段2... from-- 查詢表達(dá)式字段
select 字段1+100,字段2+字段3 from-- 別名
select 字段1 別名1, 字段2 別名2 from-- 去重DISTINCT
select distinct 字段 from-- 排序ORDER BY
select * fromorder by 排序字段
-- 條件查詢WHERE:
-- (1)比較運(yùn)算符 (2)BETWEEN ... AND ... (3)IN (4)IS NULL (5)LIKE (6)AND (7)OR 
(8)NOT
select * fromwhere 條件
  • 修改
updateset 字段1=value1, 字段2=value2... where 條件
  • 刪除
delete fromwhere 條件
http://www.risenshineclean.com/news/23203.html

相關(guān)文章:

  • 公司核名在哪個(gè)網(wǎng)站如何進(jìn)入網(wǎng)站
  • 網(wǎng)站建設(shè)新聞發(fā)布注意武漢seo公司出 名
  • 合肥網(wǎng)站推廣公司湖南正規(guī)seo公司
  • 高唐企業(yè)做網(wǎng)站推廣網(wǎng)絡(luò)服務(wù)器多少錢一臺
  • 做短視頻的網(wǎng)站收益北京seo公司網(wǎng)站
  • 用html制作網(wǎng)頁青島seo關(guān)鍵詞
  • 簡歷設(shè)計(jì)網(wǎng)官網(wǎng)手機(jī)seo百度點(diǎn)擊軟件
  • 廣州微網(wǎng)站建設(shè)效果長尾關(guān)鍵詞挖掘工具
  • 精品在線開發(fā)網(wǎng)站建設(shè)百度網(wǎng)盤官方網(wǎng)站
  • 服務(wù)一流的做網(wǎng)站短鏈接在線生成器
  • 深圳做網(wǎng)站(官網(wǎng))網(wǎng)頁設(shè)計(jì)制作網(wǎng)站教程
  • 網(wǎng)站制作com cn域名有什么區(qū)別百度認(rèn)證營銷顧問
  • 建站之星怎么免費(fèi)做網(wǎng)站網(wǎng)站百度收錄查詢
  • 企業(yè)公司做網(wǎng)站網(wǎng)絡(luò)推廣代理怎么做
  • 怎樣做克隆網(wǎng)站濟(jì)南網(wǎng)絡(luò)推廣公司
  • 沭陽住房城鄉(xiāng)建設(shè)局網(wǎng)站杭州seo搜索引擎優(yōu)化
  • 深圳網(wǎng)站策劃核心關(guān)鍵詞和長尾關(guān)鍵詞舉例
  • 從化市網(wǎng)站建設(shè)杭州網(wǎng)絡(luò)推廣有限公司
  • 國內(nèi)大型餐飲網(wǎng)站建設(shè)友情鏈接也稱為
  • 網(wǎng)站做跳轉(zhuǎn)南昌seo計(jì)費(fèi)管理
  • 網(wǎng)站建設(shè)做什么seo策略主要包括
  • 網(wǎng)站建設(shè)公司網(wǎng)站模版網(wǎng)頁代碼
  • 什么是網(wǎng)站銷售網(wǎng)站seo資訊
  • 網(wǎng)站制作怎么樣提供會員注冊網(wǎng)店推廣營銷方案
  • 做網(wǎng)站怎么做小圖標(biāo)免費(fèi)做網(wǎng)站怎么做網(wǎng)站
  • 網(wǎng)站宣傳的好處chrome 谷歌瀏覽器
  • 萊陽網(wǎng)站建設(shè)阿拉營銷網(wǎng)站
  • 前端工程師是做網(wǎng)站嗎sem廣告
  • php中網(wǎng)站不同模板后臺邏輯代碼怎么管理免費(fèi)網(wǎng)站注冊com
  • 搞網(wǎng)站網(wǎng)站交換鏈接友情鏈接的作用