成人国产在线小视频_日韩寡妇人妻调教在线播放_色成人www永久在线观看_2018国产精品久久_亚洲欧美高清在线30p_亚洲少妇综合一区_黄色在线播放国产_亚洲另类技巧小说校园_国产主播xx日韩_a级毛片在线免费

資訊專欄INFORMATION COLUMN

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

Julylovin / 2415人閱讀

數(shù)據(jù)庫(kù)的操作總結(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.檢索表中多列的記錄,列名之間用逗號(hào)分開(kāi)
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ù)是一樣的,如果想要檢索時(shí)不想出現(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后面可以跟兩個(gè)值, 第一個(gè)為起始位置, 第二個(gè)是要檢索的行數(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開(kāi)始后的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)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請(qǐng)注明本文地址:http://systransis.cn/yun/17882.html

相關(guān)文章

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

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

    _ivan 評(píng)論0 收藏0

發(fā)表評(píng)論

0條評(píng)論

最新活動(dòng)
閱讀需要支付1元查看
<