數據庫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 閱讀(295) 評論(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

          生活保健

          解析文件

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 福建省| 沙河市| 丰原市| 卢氏县| 新化县| 榆树市| 资中县| 徐水县| 宜丰县| 罗江县| 秀山| 交城县| 长春市| 崇仁县| 武穴市| 若羌县| 博湖县| 灵武市| 前郭尔| 西乌| 油尖旺区| 阜新市| 秦安县| 涟源市| 太仓市| 托克托县| 岚皋县| 渝中区| 闸北区| 聂拉木县| 肇东市| 阿克陶县| 通城县| 汾阳市| 庐江县| 札达县| 山阴县| 信宜市| 盐亭县| 庄浪县| 清苑县|