數據庫SQL語句(個人小結)

          1)
          select Cno,COUNT(Sno)
          from sc
          group by Cno;
          分析:該語句對查詢結果按Cno的值分組,所有相同Cno值的元組為一組
          然后對每一組作用集函數COUNT計算,以求得該組的學生人數。
          如果分組后還要求按一定的條件對這些組進行篩選,最終只輸出滿足指定條件的組,則可以使用HAVING
          短語指定篩選條件。

          select Cno,COUNT(Sno)
          from sc
          group by Cno
          having? COUNT(*)〉3;

          select *
          from Student
          where Sno = '9500';

          2)
          兩個表的查詢。
          seclect? ?Student.*,SC.*
          from Student,SC
          where? Student.Sno = SC.Sno;
          3)
          外連接
          select Student.Sno,Sname,Ssex,Sage,Sdept,Cno,Grade
          from Student,SC
          where Student.Sno = SC.Sno(*)
          4)
          帶有IN謂詞的子查詢
          例:
          查詢與“劉晨”在同一個系學習的學生
          select Sno,Sname,Sdept
          from Student
          where Sdept IN
          ????????? (select Stept
          ??????????? from Student
          ??????????? Where Sname = '劉晨');
          方法2:
          select S1.Sno,S1.Sname,S1.Sdept
          from Student S1,Student S2
          where S1.Sdept = S2.Sdept ?and? S2.Sname = '劉晨';
          5)
          對查詢結果排序
          select?? Sno,Grade
          from? SC
          where? Cno? =? '3'
          order? by? grade? desc;
          6)
          查詢學生總人數
          select? ?count(*)
          from?? Student;

          計算1號課程的最高成績
          select max(Grade)
          from SC
          where? Cno? = '1';??? //avg(),sum()一列值的總和。count()統計元組個數。

          7)
          Statement stmt=con.createStatement();

          stmt.executeUpdate("Update bookTable set Title='Java2' where Author='zhang'");



          stmt.executeUpdate("Delete from bookTable where Author='zhang'");

          stmt.executeUpdate("Insert into bookTable(BookID,Author,Title) values(1,'Li Ming','Java2')"); //未給出的列,其值為NULL

          posted on 2006-12-25 21:51 youngturk 閱讀(296) 評論(0)  編輯  收藏 所屬分類: 個人隨筆總結

          <2006年12月>
          262728293012
          3456789
          10111213141516
          17181920212223
          24252627282930
          31123456

          導航

          統計

          公告

          this year :
          1 jQuery
          2 freemarker
          3 框架結構
          4 口語英語

          常用鏈接

          留言簿(6)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          相冊

          EJB學習

          Flex學習

          learn English

          oracle

          spring MVC web service

          SQL

          Struts

          生活保健

          解析文件

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 石泉县| 永胜县| 抚顺县| 改则县| 上虞市| 天水市| 渭源县| 内丘县| 顺平县| 奎屯市| 宜城市| 内江市| 淳化县| 宣化县| 黄骅市| 怀仁县| 蓝田县| 若尔盖县| 商南县| 平江县| 黑河市| 洪洞县| 体育| 镇康县| 广饶县| 邢台市| 合阳县| 东至县| 新平| 周宁县| 日喀则市| 大安市| 益阳市| 尼玛县| 东辽县| 吉安市| 定日县| 蒙自县| 白银市| 合阳县| 岗巴县|