乾陑撮扲蚳戲蚳枙

蚚SQL輛俴И杶脤戙

晡翹ㄩ乾陑 懂埭ㄩ乾陑 樓?輮掉銫?2007爛04堎30??
晡猁ㄩ
蚚SQL輛俴И杶脤戙


    婓select脤戙逄曆爵褫眕И?褭elect脤戙逄曆ㄛ備峈И杶脤戙﹝衄虳抎奻蔚囀И腔select逄曆備峈赽脤戙ㄛ赽脤戙倛傖腔賦彆衱傖峈虜脤戙腔沭璃﹝
    赽脤戙褫眕И杶嗣脯ㄛ赽脤戙紱釬腔杅擂桶褫眕岆虜脤戙祥紱釬腔杅擂桶﹝赽脤戙笢祥夔衄order by煦郪逄#

蚚SQL輛俴И杶脤戙

桴萸ㄩ乾陑笱赽苤痔尪 壽瑩趼ㄩ蚚SQL輛俴И杶脤戙

蚚SQL輛俴И杶脤戙


    婓select脤戙逄曆爵褫眕И?褭elect脤戙逄曆ㄛ備峈И杶脤戙﹝衄虳抎奻蔚囀И腔select逄曆備峈赽脤戙ㄛ赽脤戙倛傖腔賦彆衱傖峈虜脤戙腔沭璃﹝
    赽脤戙褫眕И杶嗣脯ㄛ赽脤戙紱釬腔杅擂桶褫眕岆虜脤戙祥紱釬腔杅擂桶﹝赽脤戙笢祥夔衄order by煦郪逄曆﹝
4.4.1 潠等И杶脤戙
    婓▽韜鍔晤憮⑹▼硒俴狟蹈逄曆﹝
    求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求
    select emp.empno,emp.ename,emp.job,emp.sal from scott.emp where sal>=(select sal from scott.emp where ename=WARD);     求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求
    等僻▽硒俴▼偌聽ㄛ堤珋?褉?4.19垀尨腔賦彆﹝
    ▽統獗嫖攫恅璃▼ㄩ\菴4梒\4.4\441.sql﹝

    婓涴僇測鎢笢ㄛ赽脤戙select sal from scott.emp where ename=WARD腔漪砱岆植emp杅擂桶笢脤戙俷靡峈WARD腔埜馱腔郇阨ㄛ虜脤戙腔漪砱岆猁梑堤emp杅擂桶笢郇阨湮衾脹衾WARD腔郇阨腔埜馱﹝奻醱腔脤戙徹最脹歎衾謗祭腔硒俴徹最﹝
    ㄗ1ㄘ硒俴※select sal from scott.emp where ename=WARD§ㄛ腕堤sal=1250˙
    ㄗ2ㄘ硒俴※select emp.empno,emp.ename,emp.job,emp.sal from scott.emp where sal>=1250;§
4.4.2 湍▽in▼腔И杶脤戙
    婓▽韜鍔晤憮⑹▼硒俴狟蹈逄曆﹝
    求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求
    select emp.empno,emp.ename,emp.job,emp.sal from scott.emp where sal in (select sal from scott.emp where     ename=WARD);
    求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求
    等僻▽硒俴▼偌聽ㄛ堤珋?褉?4.20垀尨腔賦彆﹝
    ▽統獗嫖攫恅璃▼ㄩ\菴4梒\4.4\442.sql﹝

    奻扴逄曆俇傖腔岆脤戙郇阨睿WARD眈脹腔埜馱ㄛ珩褫眕妏蚚▽not in▼懂輛俴脤戙﹝ 4.4.3 湍▽any▼腔И杶脤戙
    婓▽韜鍔晤憮⑹▼硒俴狟蹈逄曆﹝
    求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求
    select emp.empno,emp.ename,emp.job,emp.sal from scott.emp where sal >any(select sal from scott.emp where     job=MANAGER);
    求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求
    等僻▽硒俴▼偌聽ㄛ堤珋?褉?4.21垀尨腔賦彆﹝
    ▽統獗嫖攫恅璃▼ㄩ\菴4梒\4.4\443.sql﹝

    湍any腔脤戙徹最脹歎衾謗祭腔硒俴徹最﹝
    ㄗ1ㄘ硒俴※select sal from scott.emp where job=MANAGER§,む賦彆?褉?4.22垀尨﹝
    ▽統獗嫖攫恅璃▼ㄩ\菴4梒\4.4\443-1.sql﹝

    ㄗ2ㄘ脤戙善3跺郇阨硉2975﹜2850睿2450ㄛ虜脤戙硒俴狟蹈逄曆﹝
    ▽統獗嫖攫恅璃▼ㄩ\菴4梒\4.4\443-2.sql﹝
    求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求
    select emp.empno,emp.ename,emp.job,emp.sal from scott.emp where sal >2975 or sal>2850 or sal>2450;     求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求
4.4.4 湍▽some▼腔И杶脤戙
    婓▽韜鍔晤憮⑹▼硒俴狟蹈逄曆﹝
    求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求
    select emp.empno,emp.ename,emp.job,emp.sal from scott.emp where sal =some(select sal from scott.emp where     job=MANAGER);
    求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求
    等僻▽硒俴▼偌聽ㄛ堤珋?褉?4.23垀尨腔賦彆﹝
    ▽統獗嫖攫恅璃▼ㄩ\菴4梒\4.4\444.sql﹝
    湍some腔И杶脤戙迵any腔祭紬眈肮﹝
    ㄗ1ㄘ赽脤戙,硒俴※select sal from scott.emp where job=MANAGER§,む賦彆?褉?4.22垀尨﹝
    ㄗ2ㄘ虜脤戙硒俴狟蹈逄曆﹝
    求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求
    select emp.empno,emp.ename,emp.job,emp.sal from scott.emp where sal =2975 or sal=2850 or sal=2450;     求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求
    ▽統獗嫖攫恅璃▼ㄩ\菴4梒\4.4\444-2.sql﹝

    湍▽any▼腔И杶脤戙睿▽some▼腔И杶脤戙髡夔岆珨欴腔﹝婌ぶ腔SQL躺躺埰勍妏蚚▽any▼ㄛ綴懂腔唳掛峈賸睿荎逄腔▽any▼眈⑹煦ㄛ竘?蹅芊駒ome▼ㄛ肮奀遜悵隱賸▽any▼壽瑩棵﹝
4.4.5 湍▽all▼腔И杶脤戙
    婓▽韜鍔晤憮⑹▼硒俴狟蹈逄曆﹝
    求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求
    select emp.empno,emp.ename,emp.job,emp.sal from scott.emp where sal >all(select sal from scott.emp where     job=MANAGER);
    求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求
    等僻▽硒俴▼偌聽ㄛ堤珋?褉?4.24垀尨腔賦彆﹝
    ▽統獗嫖攫恅璃▼ㄩ\菴4梒\4.4\445.sql﹝

    湍all腔И杶脤戙迵▽some▼腔祭紬眈肮﹝
    ㄗ1ㄘ赽脤戙ㄛ賦彆?褉?4.22垀尨﹝
    ㄗ2ㄘ虜脤戙硒俴狟蹈逄曆﹝
    求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求
    select emp.empno,emp.ename,emp.job,emp.sal from scott.emp where sal >2975 and sal>2850 and sal>2450;
    求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求
    ▽統獗嫖攫恅璃▼ㄩ\菴4梒\4.4\445-2.sql﹝
4.4.6 湍▽exists▼腔И杶脤戙
    婓▽韜鍔晤憮⑹▼硒俴狟蹈逄曆﹝
    求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求
    select emp.empno,emp.ename,emp.job,emp.sal from scott.emp,scott.dept where exists (select * from scott.emp where     scott.emp.deptno=scott.dept.deptno);
    求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求
    等僻▽硒俴▼偌聽ㄛ堤珋?褉?4.25垀尨腔賦彆﹝
    ▽統獗嫖攫恅璃▼ㄩ\菴4梒\4.4\446.sql﹝

4.4.7 甜紱釬腔И杶脤戙
    甜紱釬憩岆摩磁笢甜摩腔衙癩﹝扽衾摩磁A麼摩磁B腔啋匼軞睿憩岆甜摩﹝ 婓▽韜鍔晤憮⑹▼硒俴狟蹈逄曆﹝
    求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求
     (select deptno from scott.emp) union (select deptno from scott.dept);     求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求
    等僻▽硒俴▼偌聽ㄛ堤珋?褉?4.26垀尨腔賦彆﹝
    ▽統獗嫖攫恅璃▼ㄩ\菴4梒\4.4\447.sql﹝

4.4.8 蝠紱釬腔И杶脤戙
    蝠紱釬憩岆摩磁笢蝠摩腔衙癩﹝扽衾摩磁Aй扽衾摩磁B腔啋匼軞睿憩岆蝠摩﹝ 婓▽韜鍔晤憮⑹▼硒俴狟蹈逄曆﹝
    求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求
    (select deptno from scott.emp) intersect (select deptno from scott.dept);     求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求
    等僻▽硒俴▼偌聽ㄛ堤珋?褉?4.27垀尨腔賦彆﹝
    ▽統獗嫖攫恅璃▼ㄩ\菴4梒\4.4\448.sql﹝

4.4.9 船紱釬腔И杶脤戙
    船紱釬憩岆摩磁笢船摩腔衙癩﹝扽衾摩磁Aй祥扽衾摩磁B腔啋匼軞睿憩岆船摩﹝
    婓▽韜鍔晤憮⑹▼硒俴狟蹈逄曆﹝
    求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求
    (select deptno from scott.dept) minus (select deptno from scott.emp);
    求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求
    等僻▽硒俴▼偌聽ㄛ堤珋?褉?4.28垀尨腔賦彆﹝
    ▽統獗嫖攫恅璃▼ㄩ\菴4梒\4.4\449.sql﹝

    甜﹜蝠睿船紱釬腔И杶脤戙猁⑴扽俶撿衄眈肮腔隅砱ㄛ婦嬤濬倰睿?>絲僇均?

蛌婥ㄩ蛌婥③悵隱掛陓洘,掛恅懂赻http://www.51dibs.com/lp07/la/a2/l_a_a56a0eceee9bae9e.html