<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    想飛就別怕摔

    大爺的并TM罵人

    SQL語句整理[第二章](學習筆記)

     廢話少說用例子來說話。
    1.create database sqltest    //創建數據庫;

    2.create table students (sno numeric(6,0)not null,sname varchar(8)not null,age numeric(3,0),
    sex char(2),bplace varchar(20),primary key(sno))  
     //創建表students;

    3.create table courses (cno char(4)not null,cname varchar(10)not null,credit int)
    //創建表courses;

    4.alter table courses add primary key (cno)  
    //為courses表的cno字段添加主鍵約束;

    5.create table enrools(sno numeric(6,0)not null,cno char(4)not null,grade int,primary key(sno,cno),
    foreign key(sno)references students(sno),foreign key(cno) references courses(cno))   
    //創建表enrools,并添加主外鍵約束;

    6.select sno,sname,age into girl from students where sex='女'   
    //根據Student表創建gril表,字段為3個;

    7.create view faculty as select sno,age,sname from students   
    //根據Student表創建視圖;

    8.create view grade_table as select sname,cname,grade from students,enrools,courses where students.sno=enrools.sno and courses.cno=enrools.cno   
    //從Student、enrools、courses 表中產生一視圖,包括sname、cname、grade;

    9.drop view grade_table    
    //刪除視圖;

    10.select cno,cname from courses where credit=3  
    //在表courses中找出3個學分的cno,cname;

    11.select * from students where age >22    
    //在Student表中找出age大于22的學生狀況;

    12.select sname,age from students where sex='男' and bplace='北京'  
    //在Student表中找出北京籍男生的sname,age;

    13.select sno,sname,age from students age between 20 and 23 order by age   
     //找出年齡在20~23之間的學生的sno,sname,age;

    14.select sname,sex from students where age<23 and bplace in('北京','上海')   
     //找出年齡小與23北京上海的學生的sname,sex;

    15.select * from students where sname like '張%'   
     //找出姓張同學的狀況;

    16.select sname from students where  sno=(select sno from enrools where  grade=95)   
     //找出學分為95分的同學姓名,只限查找一條記錄(子查詢);

    17.select sname from students where sno=any(select sno from enrools where grade>90)
    或者select sname from students where sno in(select sno from enrools where grade>90)    
    //找出學分為90分的同學姓名,查找多條記錄(子查詢);

    18.select sname,cno,grade from students,enrools where students.sno=enrools.sno   
    //查找全部學生的姓名,課程號,成績;(連接查詢);


    19.select sname,bplace,grade from student,enrools where bplace in ('北京','上海') and grade>90 and students.sno=enrools.sno
    //找出籍貫是北京或上海,成績在90分以上的學生sname,bpalce,grade;

    20.select min(age) from students    
    //找出年齡最小的學生;

    21.select count(*) from students where age<=22   
     //找出年齡小于等于22的學生人數;

    22.select avg(grade),courses=count(*) from enrools group by son   
     //找出學生的平均成績和課程門數;

    23.select sname from students where age>(select avg(age) from students)    
    //找出年齡大于平均年齡的學生名字;

    24.select con, avg(grade), students=count(*)  from enrools group by con ,having count(*)>=3    
    //找出個課程的平均成績,按課程號分組,且只選擇課程號超過3個的成績;(GROUP BY子句把一個表按某一指定列(或一些列)上的值相等的原則分組,然后再對每組。GROUP BY 子句總是跟在 Where 子句后面,當 Where 子句缺省時,它跟在 FROM 子句后面。HAVING 子句常用于在計算出聚集之后對行的查詢進行控制。

    25.select sname,sno from students where not exists (select * from enrools where students.sno=enrools.sno)    
    //查詢沒有任何課程學生的學號和姓名(
    當一個子查詢涉及到一個來自外部查詢的列時,稱為相關子查詢correlated Subquery 。相關子查詢要用到存在測試謂詞EXISTS 和 NOT EXISTS 及 ALL 、 ANY ( SOME )等。);

    26.select * from students where bplace='北京' natural join (select * from enrools where grade>=80) 
    //查詢籍貫是北京,成績在80分以上的學生信息;

    27.inster into students values (009901,'張三',23,'男','北京')    
    //插入學生信息;

    28.inster into teachers (tno,tname) select distinct sno,sname from students,enrools where students.sno=enrools .sno and grade>90   
     // 把成績大于90的同學加入到教師的表中,留校。

    29.update students set age=age+1  
    //所有學生年齡加1;

    30.update enrolls set grade=0 where con='c1' and '張三'=(select sname from students where students.sno=enrools.sno)   
     //把張三的成績改為0;

    31.delete from students where age>30   
     //刪除年齡大于30的學生資料;







     

    posted on 2008-09-25 15:31 生命的綻放 閱讀(389) 評論(0)  編輯  收藏 所屬分類: 數據庫

    <2008年9月>
    31123456
    78910111213
    14151617181920
    21222324252627
    2829301234
    567891011

    導航

    統計

    常用鏈接

    留言簿(5)

    隨筆分類(94)

    隨筆檔案(93)

    文章分類(5)

    文章檔案(5)

    相冊

    JAVA之橋

    SQL之音

    兄弟之窗

    常用工具下載

    積分與排名

    最新評論

    閱讀排行榜

    主站蜘蛛池模板: 黄色网页在线免费观看| 91在线亚洲精品专区| 亚洲a∨无码精品色午夜| 亚洲一区二区三区免费视频| 久久亚洲国产成人精品性色 | 色天使色婷婷在线影院亚洲| 搡女人真爽免费视频大全| 亚洲国产精品免费观看| 无码视频免费一区二三区| 国产成人精品日本亚洲语音 | 毛片免费视频观看| 亚洲另类无码一区二区三区| 国产男女猛烈无遮档免费视频网站 | 特黄特色的大片观看免费视频| 亚洲国产成人久久一区久久| 亚洲第一视频在线观看免费| 国产aⅴ无码专区亚洲av| 91香蕉国产线观看免费全集| jlzzjlzz亚洲jzjzjz| 日韩在线免费电影| 深夜久久AAAAA级毛片免费看| 亚洲欧洲美洲无码精品VA| 114级毛片免费观看| 亚洲av中文无码乱人伦在线观看| 全黄性性激高免费视频| 国产免费网站看v片在线| 亚洲性无码av在线| 免费大香伊蕉在人线国产| 青青草原1769久久免费播放| 亚洲大香伊人蕉在人依线| 亚洲 国产 图片| 午夜爽爽爽男女免费观看影院| 一本色道久久综合亚洲精品蜜桃冫 | 亚洲第一男人天堂| 亚洲一区日韩高清中文字幕亚洲 | 最近2019中文免费字幕在线观看| 亚洲精品国产第1页| 免费h成人黄漫画嘿咻破解版| a毛片全部免费播放| 亚洲午夜无码久久久久小说 | 亚洲色婷婷综合开心网|