华南俳烁实业有限公司

考試首頁 | 考試用書 | 培訓課程 | 模擬考場 | 考試論壇  
全國  |             |          |          |          |          |         
  當前位置:計算機等級 > 二級考試 > MySQL數(shù)據(jù)程序設(shè)計 > MySQL 輔導 > 文章內(nèi)容
  

全國計算機等級考試二級MySQL教程(52)

中華IT學院   【 】  [ 2016年2月20日 ]

我們在TUTORIALS數(shù)據(jù)庫中有兩張表 tcount_tbl 和 tutorials_tbl。兩張數(shù)據(jù)表數(shù)據(jù)如下:

實例

嘗試以下實例:

root@host# mysql -u root -p password;
Enter password:*******
mysql> use TUTORIALS;
Database changed
mysql> SELECT * FROM tcount_tbl;
+-----------------+----------------+
| tutorial_author | tutorial_count |
+-----------------+----------------+
| mahran          |             20 |
| mahnaz          |           NULL |
| Jen             |           NULL |
| Gill            |             20 |
| John Poul       |              1 |
| Sanjay          |              1 |
+-----------------+----------------+
6 rows in set (0.01 sec)
mysql> SELECT * from tutorials_tbl;
+-------------+----------------+-----------------+-----------------+
| tutorial_id | tutorial_title | tutorial_author | submission_date |
+-------------+----------------+-----------------+-----------------+
|           1 | Learn PHP      | John Poul       | 2007-05-24      |
|           2 | Learn MySQL    | Abdul S         | 2007-05-24      |
|           3 | JAVA Tutorial  | Sanjay          | 2007-05-06      |
+-------------+----------------+-----------------+-----------------+
3 rows in set (0.00 sec)
mysql>

接下來我們就使用MySQL的JOIN來連接以上兩張表來讀取tutorials_tbl表中所有tutorial_author字段在tcount_tbl表對應(yīng)的tutorial_count字段值:

mysql> SELECT a.tutorial_id, a.tutorial_author, b.tutorial_count
    -> FROM tutorials_tbl a, tcount_tbl b
    -> WHERE a.tutorial_author = b.tutorial_author;
+-------------+-----------------+----------------+
| tutorial_id | tutorial_author | tutorial_count |
+-------------+-----------------+----------------+
|           1 | John Poul       |              1 |
|           3 | Sanjay          |              1 |
+-------------+-----------------+----------------+
2 rows in set (0.01 sec)
mysql>
分享到:
本文糾錯】【告訴好友】【打印此文】【返回頂部
將考試網(wǎng)添加到收藏夾 | 每次上網(wǎng)自動訪問考試網(wǎng) | 復制本頁地址,傳給QQ/MSN上的好友 | 申請鏈接 | 意見留言 TOP
關(guān)于本站  網(wǎng)站聲明  廣告服務(wù)  聯(lián)系方式  站內(nèi)導航  考試論壇
Copyright © 2007-2013 中華考試網(wǎng)(Examw.com) All Rights Reserved
海林市| 吉安县| 台湾省| 博白县| 萨迦县| 碌曲县| 岗巴县| 灵台县| 那曲县| 安化县| 闽侯县| 手游| 仁化县| 榆树市| 泾源县| 滁州市| 玉溪市| 晋州市| 潢川县| 盐源县| 扬中市| 德江县| 准格尔旗| 青冈县| 高安市| 惠水县| 青海省| 阿克| 定西市| 固阳县| 化德县| 高雄市| 容城县| 深水埗区| 洞口县| 海盐县| 龙陵县| 信阳市| 柏乡县| 全南县| 岳池县|