<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之音

    兄弟之窗

    常用工具下載

    積分與排名

    最新評論

    閱讀排行榜

    主站蜘蛛池模板: 免费在线视频你懂的| 日本免费一区二区三区| 国产小视频免费观看| 亚洲av永久无码嘿嘿嘿| 亚洲免费在线观看视频| 亚洲国产精品成人精品小说 | 一级特黄录像免费播放中文版| 日韩中文无码有码免费视频 | 国产亚洲精品免费视频播放 | 亚洲精品午夜国产va久久| 4399好看日本在线电影免费| 亚洲国产精品网站久久| 免费人成视频在线| 亚洲第一综合天堂另类专| 国产精品国产自线拍免费软件 | 毛片在线全部免费观看| 亚洲嫩模在线观看| 国产福利在线免费| 国产精品亚洲一区二区三区久久| 免费中文字幕一级毛片| 香蕉视频在线免费看| 亚洲A∨无码无在线观看| 在线永久免费的视频草莓| 亚洲AV无码国产精品永久一区| 亚洲女同成人AⅤ人片在线观看| 国内永久免费crm系统z在线| 亚洲神级电影国语版| 日本免费无遮挡吸乳视频电影| 四虎影视久久久免费观看| 亚洲av永久无码制服河南实里| 免费黄色网址网站| 香蕉视频亚洲一级| 亚洲精选在线观看| 日本午夜免费福利视频| 美女视频黄的免费视频网页| 亚洲成_人网站图片| 亚洲中文字幕久久精品无码喷水| 91精品免费久久久久久久久| 老妇激情毛片免费| 亚洲无圣光一区二区| 亚洲区小说区图片区|