成人无码视频,亚洲精品久久久久av无码,午夜精品久久久久久毛片,亚洲 中文字幕 日韩 无码

資訊專欄INFORMATION COLUMN

MySQL學(xué)習(xí)筆記之二

Julylovin / 2461人閱讀

數(shù)據(jù)庫的操作總結(jié)就是:增刪改查(CURD),今天記錄一下基礎(chǔ)的檢索查詢工作。

檢索MySQL
1.查詢表中所有的記錄
mysql> select * from apps;
+----+------------+-----------------------+---------+
| id | app_name   | url                   | country |
+----+------------+-----------------------+---------+
|  1 | QQ APP     | http://im.qq.com      | CN      |
|  2 | 微博 APP   | http://weibo.com      | CN      |
|  3 | 淘寶 APP   | http://www.taobao.com | CN      |
+----+------------+-----------------------+---------+
3 rows in set (0.00 sec)
2. 查詢表中某列(單列)的記錄
mysql> select app_name from apps;
+------------+
| app_name   |
+------------+
| QQ APP     |
| 微博 APP   |
| 淘寶 APP   |
+------------+
3 rows in set (0.00 sec)
3.檢索表中多列的記錄,列名之間用逗號分開
mysql> select id, app_name from apps;
+----+------------+
| id | app_name   |
+----+------------+
|  1 | QQ APP     |
|  2 | 微博 APP   |
|  3 | 淘寶 APP   |
+----+------------+
3 rows in set (0.00 sec)
4.檢索不重復(fù)的記錄,distinct關(guān)鍵字
mysql> select * from apps;
+----+------------+-----------------------+---------+
| id | app_name   | url                   | country |
+----+------------+-----------------------+---------+
|  1 | QQ APP     | http://im.qq.com      | CN      |
|  2 | 微博 APP   | http://weibo.com      | CN      |
|  3 | 淘寶 APP   | http://www.taobao.com | CN      |
|  4 | QQ APP     | http://im.qq.com      | CN      |
+----+------------+-----------------------+---------+
4 rows in set (0.00 sec)
上面表中是所有的數(shù)據(jù),可以看到第1條和第4條數(shù)據(jù)是一樣的,如果想要檢索時不想出現(xiàn)重復(fù)的數(shù)據(jù),可以使用distinct關(guān)鍵字,并且需要放在所有列的前面
mysql> select distinct app_name from apps;
+------------+
| app_name   |
+------------+
| QQ APP     |
| 微博 APP   |
| 淘寶 APP   |
+------------+
3 rows in set (0.00 sec)
5.限制檢索記錄的數(shù)量, limit關(guān)鍵字
mysql> select * from apps limit 2;
+----+------------+------------------+---------+
| id | app_name   | url              | country |
+----+------------+------------------+---------+
|  1 | QQ APP     | http://im.qq.com | CN      |
|  2 | 微博 APP   | http://weibo.com | CN      |
+----+------------+------------------+---------+
2 rows in set (0.00 sec)

limit后面可以跟兩個值, 第一個為起始位置, 第二個是要檢索的行數(shù)
mysql> select * from apps limit 1, 2;
+----+------------+-----------------------+---------+
| id | app_name   | url                   | country |
+----+------------+-----------------------+---------+
|  2 | 微博 APP   | http://weibo.com      | CN      |
|  3 | 淘寶 APP   | http://www.taobao.com | CN      |
+----+------------+-----------------------+---------+
2 rows in set (0.00 sec)
5.limit關(guān)鍵字和offset配合使用
limit可以配合offset使用, 如limit 2 offset 1(從行1開始后的2行,默認(rèn)行數(shù)的角標(biāo)為0)
mysql> select * from apps limit 2 offset 1;
+----+------------+-----------------------+---------+
| id | app_name   | url                   | country |
+----+------------+-----------------------+---------+
|  2 | 微博 APP   | http://weibo.com      | CN      |
|  3 | 淘寶 APP   | http://www.taobao.com | CN      |
+----+------------+-----------------------+---------+
2 rows in set (0.00 sec)

我的網(wǎng)站:https://wayne214.github.io

文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請注明本文地址:http://m.hztianpu.com/yun/17882.html

相關(guān)文章

  • Codeigniter 4.0-dev 版源碼學(xué)習(xí)筆記之二——入口以及初始化操作

    摘要:通過這個函數(shù)可以很方便的在程序運(yùn)行期間執(zhí)行很多常見操作。此文可以轉(zhuǎn)載,但轉(zhuǎn)載前需要發(fā)郵件到進(jìn)行溝通,未溝通的均視作侵權(quán)。 index.php index.php 是整個框架的入口文件,也就是說所有的請求都要從它這里開始。因為 index.php 源碼非常簡潔,那么我們直接放一張源碼截圖,按著截圖說一下源碼。 showImg(https://segmentfault.com/img/re...

    _ivan 評論0 收藏0

發(fā)表評論

0條評論

閱讀需要支付1元查看
<