<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                ## 先看個問題 * 問:查詢每個學生每個科目的分數 * 分析:學生姓名來源于students表,科目名稱來源于subjects,分數來源于scores表,怎么將3個表放到一起查詢,并將結果顯示在同一個結果集中呢? * 答:當查詢結果來源于多張表時,需要使用連接查詢 * 關鍵:找到表間的關系,當前的關系是 * students表的id---scores表的stuid * subjects表的id---scores表的subid * 則上面問題的答案是: ~~~ select students.sname,subjects.stitle,scores.score from scores inner join students on scores.stuid=students.id inner join subjects on scores.subid=subjects.id; ~~~ * 結論:當需要對有關系的多張表進行查詢時,需要使用連接join ## 連接查詢 * 連接查詢分類如下: * 表A inner join 表B:表A與表B匹配的行會出現在結果中 * 表A left join 表B:表A與表B匹配的行會出現在結果中,外加表A中獨有的數據,未對應的數據使用null填充 * 表A right join 表B:表A與表B匹配的行會出現在結果中,外加表B中獨有的數據,未對應的數據使用null填充 * 在查詢或條件中推薦使用“表名.列名”的語法 * 如果多個表中列名不重復可以省略“表名.”部分 * 如果表的名稱太長,可以在表名后面使用' as 簡寫名'或' 簡寫名',為表起個臨時的簡寫名稱 ## 練習 * 查詢學生的姓名、平均分 ~~~ select students.sname,avg(scores.score) from scores inner join students on scores.stuid=students.id group by students.sname; ~~~ * 查詢男生的姓名、總分 ~~~ select students.sname,avg(scores.score) from scores inner join students on scores.stuid=students.id where students.gender=1 group by students.sname; ~~~ * 查詢科目的名稱、平均分 ~~~ select subjects.stitle,avg(scores.score) from scores inner join subjects on scores.subid=subjects.id group by subjects.stitle; ~~~ * 查詢未刪除科目的名稱、最高分、平均分 ~~~ select subjects.stitle,avg(scores.score),max(scores.score) from scores inner join subjects on scores.subid=subjects.id where subjects.isdelete=0 group by subjects.stitle; ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看