Ch07 SQL Statement

Embed Size (px)

Citation preview

  • 8/13/2019 Ch07 SQL Statement

    1/26

    saklviTaly ebolR)ay Build Bright University

    Chapter VII

    SQL Statement

    kgEpkenHeyIgsikSaGMBI SQLvaCYykgkarTMnakTMngrvag Program nigDatabase!

    I. Definition:

    + SQL : Ca"asaE#lCYyeGayUser

    Ga$e%&IkargarCa'Yy Relational Database ( Select, Insert,Delete, Update, Query, Protect ) ! SQL CaGkSrka(rbs StructureQuery Language

    + A Database is a system or storing comple!, structure inormation on hard dis"( table ,ile system ##########) #

    +A DBS is a collection o programs that enables users to create and maintain adatabase#

    + !he "e#ationa# o$e# :$he Relational Database %odel ( Ca Database E#l Data

    erobCa$able ) consist o the ollo&ing three components ' Data Structure ' Data are organi*ed in the orm o table or Relation+ Data %anipulation ' Po&erul operations such as SQ anguage or QB-

    are used to manipulate data stored in the DB#. Data integrity ' Business Rule are speciied to maintain the integrity o data

    &hen they are manipulated#+ In the "e#ationa# o$e# %a&e :

    ' $able' /olumn, ield' Ro&, record' /onstrain or integrity rule' Primary "ey' /andidate "ey

    + (rouping of SQL Statement :

    ' DD ( Data Deinition anguage ) ' Ca Statement SQeRbIsMrab/reate $able, 0ie&, Inde!, Drop $able#

    Database Design 1# /h21SQ Statement

  • 8/13/2019 Ch07 SQL Statement

    2/26

    saklviTaly ebolR)ay Build Bright University

    ' D% ( Data %anipulation anguage ) ' Ca SQ StatementeRbIsMrab Query nig/hang Data in table ' S--/$,UPD3$-, D--$-, I4S-R$#

    ' D/ ( Data /ontrol anguage ) ' D/ statement relate to the security oData ( 5R34$, /R-3$- US-R, DR6P US-R )#

    II. Create $atabase $ennis#accdb

    + Create ) tab#es in !ennis.acc$b* as be##o here :!ab#e ,

    /reate $able Players( P37-R46 S86R$ 46$ 4U, 43%- /83R ( 9 ) 46$ 4U, I4I$I3S /83R ( . ) 46$ 4U, BIR$8:D3$- D3$- , S-; /83R ( ) 46$ 4U, ) , $6?4 /83R ( 2 ) 46$ 4U, P864-46 /83R ( 2 ) 46$ 4U, -35U-46 /83R ( = ) , PRI%3R7 @-7 ( P37-R46 ) )

    !ab#e -

    /reate $able $eams( $-3%46 S86R$ 46$ 4U, P37-R46 S86R$ 46$ 4U, DI0ISI64 /83R ( > ) 46$ 4U, PRI%3R7 @-7 ( $-3%46 ) )

    !ab#e

    /reate $able %atches( %3$/846 S86R$ 46$ 4U, $-3%46 S86R$ 46$ 4U, P3746 S86R$ 46$ 4U, ?64 S86R$ 46$ 4U, 6S$ S86R$ 46$ 4U, PRI%3R7 @-7 ( %3$/846 ) )

    !ab#e /

    /reate $able Penalties( P37%-4$46 I4$-5-R 46$ 4U,

    Database Design 1#+ /h21SQ Statement

  • 8/13/2019 Ch07 SQL Statement

    3/26

    saklviTaly ebolR)ay Build Bright University

    P37-R46 S86R$ 46$ 4U, P37%-4$:D3$- D3$- 46$ 4U, 3%6U4$ D6UB- 46$ 4U, PRI%3R7 @-7 (P37%-4$46) )

    !ab#e )/reate $able /ommittee:%embers

    ( P37-R46 S86R$ 46$ 4U , B-5I4:D3$- D3$- 46$ 4U , -4D:D3$- D3$- , P6SI$I64 /83R( +2 ) , PRI%3R7 @-7 (P37%-4$46, B-5I4:D3$-))

    Qo : I4S-R$ I4$6 P37-RS03U-S ( >, AParmenterA , RA , C>= 2> +9A, %A, C11 , 8aseltineaneA ,E2A , +.=@@A , StartordA , 212 =1>9.1A , E=>1A )

    I4S-R$ I4$6 $-3%S 03U-S ( , >, FIRS$A )I4S-R$ I4$6 %3$/8S 03U-S ( , , >, ., )I4S-R$ I4$6 P-43$I-S 03U-S ( , >, CE2 + 2EA, 22 )I4S-R$ I4$6 /6%%I$$--:%-%B-RS03U-S ( >, CC2 A, CC2 + .A, SecretaryA )

    Synta0 :

    S--/$ G clause H

    FR6% G clause H

    ?8-R- G clause H

    5R6UP B7 Gclause H

    830I45 G clause H

    6RD-R B7 G clause H

    1ote :

    S--/$ statement nI'Yy'any*ag(i$bMp+(+ clause,-' S--/$ nigFR6%, $ME.k

    ?8-R-, 5R6UP B7, 6RD-R B7 R,anE(Ca6ptional $he order o the clause i i!ed '

    S--/$- FR6% ?8-R- 5R6UP B7 830I45 6RD-R B7

    III. Querying !ab#e

    Database Design 1#. /h21SQ Statement

  • 8/13/2019 Ch07 SQL Statement

    4/26

    saklviTaly ebolR)ay Build Bright University

    20 ,: 5et the number, the name, and the date o birth o each player resident in

    Stratord sort the result in alphabetical order o name ( 4ote that Stratord must be

    speciied &ith one capital letter )

    Q, :

    S--/$ P37-R46, 43%-, BIR$8:D3$-

    FR6% P37-RS

    ?8-R- $6?4JAStratord A

    6RD-R B7 43%-

    20 - : 5et the number o every player &ho Koined the club ater CE2 and is resident

    in Stratord order the result by player number#

    Q- :

    S--/$ P37-R46

    FR6% P37-RS

    ?8-R-

  • 8/13/2019 Ch07 SQL Statement

    5/26

    saklviTaly ebolR)ay Build Bright University

    S-$ 3%6U4$ J+22

    ?8-R- Player4o J ==

    $he eect o the change can be seen by issuing a S--/$ statement '

    S--/$ L FR6% P-43$I-S

    20 ) :Remove each penalty &here the amount is greater than 22 ( ?e assume the

    changed contents o the P-43$I-S $able ) '

    Q) :

    D--$-

    FR6% P-43$I-S

    ?8-R- 3%6U4$ H 92

    6ptimi*ing Nuery processing

    20 4 :5et all inormation about each penalty, &hen amountJ+9 '

    Q4 :

    S--/$ L

    FR6% P-43$I-S

    ?8-R- 3%6U4$ J +9

    20 5 : Find the age o each Player '

    Q5 :

    S--/$ P37-R46, 4ame, +22. 7ear ( Birth: Date ) 3S 3ge

    FR6% P37-RS

    20 6 : /reate the I4D-; or $ableP-43$I-S in ield 3%6U4$

    Database Design 1#9 /h21SQ Statement

  • 8/13/2019 Ch07 SQL Statement

    6/26

    saklviTaly ebolR)ay Build Bright University

    Q6 :

    /R-3$- I4D-; P-43$I-S:3%6U4$64 P-43$I-S ( 3%6U4$ )

    Q7 : + De#eting $atabase ob8ects

    Delete the %atches table'

    DR6P $3B- %3$/8S

    DR6P I4D-; P-43$I-S:3%6U4$

    V. System Variab#e: DA!2 9 * !I2 9

    S--/$ L

    FR6% P-43$I-S

    ?8-R- P37%-4$:D3$- J D3$- ( )

    VI. 1umeric 20pressions

    Q,; : Find the matches &here the number o sets &on is at least t&ice as high as the

    number o set lost '

    S--/$ L

    FR6% %3$/8-S

    ?8-R- ?64 H J 6S$ L +

    Q,,: 5ive the player number and the address o each player resident in Stratord '

    Database Design 1#> /h21SQ Statement

  • 8/13/2019 Ch07 SQL Statement

    7/26

    saklviTaly ebolR)ay Build Bright University

    S--/$ P37-R46, S$R--$ O A O 86US-46

    FR6% P37-RS

    ?8-R- $6?4 J Stratord

    Q,- : 5ive the payment number and the year o each penalty paid ater CE. '

    S--/$ P37%-4$46, 7-3R ( P37%-4$:D3$- )

    FR6% P-43$I-S

    ?8-R- 7-3R ( P37%-4$:D3$- ) H CE2

    S--/$ P37%-4$46, 7-3R ( Payment:Date ) 3s 7-3R

    FR6% P-43$I-S

    S--/$ P37%-4$46, %64$8 ( Payment:Date ) 3s %64$8

    FR6% P-43$I-S

    S--/$ P37%-4$46, D37 ( Payment:Date ) 3s D37

    FR6% P-43$I-S

    Q, : 5et the number and name o each player &hose name has e!actly seven letters,

    and order the result by player number '

    S--/$ P37-R46, 43%-

    Database Design 1#1 /h21SQ Statement

  • 8/13/2019 Ch07 SQL Statement

    8/26

    saklviTaly ebolR)ay Build Bright University

    FR6% P37-RS

    ?8-R- -4 ( 43%- ) J1

    6RD-R B7 P37-R46

    20,/: Find the player number, the se! and the name o every player &ho Koined theclub ater CE.# $he se! must be printed as FemaleA or %aleA#

    S--/$ P37-R46, 43%- ,

    IF(S-;JAFA, F-%3-A, %3-A) 3S S-; 6F P37-RFR6% P37-RS

    ?8-R-

  • 8/13/2019 Ch07 SQL Statement

    9/26

  • 8/13/2019 Ch07 SQL Statement

    10/26

    saklviTaly ebolR)ay Build Bright University

    Q,6 :

    S--/$ DIS$I4/$ $#P37-R46

    FR6% $-3%S 3S $, P-43$I-S 3S P-4

    ?8-R- $#P37-R46, J P-4#P37-R46

    Q,7 :5ive the names and initials o the player &ho have played at least one match#

    ?arning' a competition player does not have to appear in the %3$/8S table

    (perhaps he or she has been inKured or the &hole season) '

    S--/$ DIS$I4/$ P#43%-, P#I4I$I3S

    FR6% P37-RS 3S P, %3$/8S 3S %

    ?8-R- P#P37-R46 J %#P37-R46

    Q-; : For each match, give the player number, the team number, the name o the

    player and the division in &hich the team players '

    S--/$ DIS$I/$ %#P37-R46, %#$-3%46, P#43%-

    $#DI0ISI64

    FR6% %3$/8S 3S %, P37-RS 3S P, $-3%S 3S $

    ?8-R- %#P37-R46 J P#P37-R46

    34D %#$-3%46 J $#$-3%46

    1ote:$hereore, the Results o the ollo&ing t&o statements are eNuivalent '

    S--/$ P37-RS#P37-R46

    FR6% P37-RS, $-3%S

    ?8-R- P37-RS#P37-R46 J $-3%S#P37-R46

    and

    S--/$ P37-RS#P37-R46

    Database Design 1#2 /h21SQ Statement

  • 8/13/2019 Ch07 SQL Statement

    11/26

    saklviTaly ebolR)ay Build Bright University

    FR6% $-3%S, P37-RS

    ?8-R- P37-RS#P37-R46 J $-3%S#P37-R46

    Q-, :5ive the Payment4umber, Player4umber and the date o each penalty incurred

    in the year in &hich the player concerned Koined the club '

    S--/$ P-4#P37%-4$46, P-4#P37-R46,

    P-4#P37%-4$:D3$-

    FR6% P-43$I-S 3S P-4, P37-RS 3S P

    ?8-R- P-4#P37-R46 J P#P37-R46

    34D 7-3R(P-4#P37%-4$:D3$-) J P#

  • 8/13/2019 Ch07 SQL Statement

    12/26

    saklviTaly ebolR)ay Build Bright University

    - For each penalty, ind the payment number, the amount and the number and name o

    the player &ho incurred it#

    O 3ns&ers '

    S--/$ P37%-4$46, 3%6U4$, P#P37-R46, 43%-

    FR6% P-43$I-S 3S P-4, P37-RS 3S P

    ?8-R- P-4#P37-R46 J P#P37-R46

    For each penalty incurred by a team captain, ind the payment number and the

    captionAs name#

    S--/$ P37%-4$46, 43%-

    FR6% P-43$I-S 3S P-4, P37-RS 3S P, $-3%S 3S $

    ?8-R- P-4#P37-R46 J $#P37-R4634D $#P37-R46 J P#P37-R46

    / 5ive the numbers and names o the players &ho live in the same to&n as player +1

    O 3ns&er '

    S--/$ P#P37-R46, P#43%-

    FR6% P37-RS 3S P, P37-RS 3S P+1

    ?8-R- P#$6?4 J P+1#$6?4

    34D P+1#P37-R46 J +1

    34D P#P37-R46 G H +1

    ) 5ive the number and name o every competition player, as &ell as the number and

    name o the captain o each team or &hom that player has ever competed#

    $he result may not contain competition player &ho are them sel captains o a team#

    Desired result '

    P37-R46 43%-(P37-RS) P37-R46 43%-(/3P$3I4)

    == Bac"er > Parmenter

    E 4e&castle > Parmenter

    E 4e&castle +1 /ollins

    . . . .

    . . . .

    . . . .

    . . . .

    3ns&er'

    S--/$ DIS$I4/$ P#P37-R46, P#43%-, /3P#P37-R46,

    Database Design 1#+ /h21SQ Statement

  • 8/13/2019 Ch07 SQL Statement

    13/26

    saklviTaly ebolR)ay Build Bright University

    /3P#43%-

    FR6% P37-RS 3S P, P37-RS 3S /3P, %3$/8S 3S %,

    $-3%S 3S $

    ?8-R- %#P37-R46 J P#P37-R46

    34D $#$-3%46 J %#$-3%46

    34D %#P37-R46 G H $#P37-R46

    !he @peration in SQL Statement:

    ' /onditions coupled &ith 34D, 6R and 46$

    ' $he B-$?--4 operator

    ' $he I4 operator

    ' $he I@- operator' $he 4U operator

    ' $he 347 and 3 operator

    ' /omparition operations o SQ

    /6%P3RI$I6I4 6P-R3$6R %-34I45

    J eNual to

    G less than

    H greater than

    GJ less than or eNual to

    HJ greater than or eNual to

    GH not eNual to

    Q- :5ive the number, the date o birth and the player o Koining the club or each

    player &ho Koined 1 year ater he or she &as born '

    S--/$ P37-R46, BIR$8:D3$-, $6I4-D

    FR6% P37-RS

    ?8-R- 7-3R(BIR$8:D3$-) O1 J 2

    S--/$ P37-R46

    FR6% P37-RS

    ?8-R- -35U-46 J 12>2A

    Database Design 1#. /h21SQ Statement

  • 8/13/2019 Ch07 SQL Statement

    14/26

    saklviTaly ebolR)ay Build Bright University

    20ercises:

    ) For each penalty ind the payment number &here the amount is more than M>2 ( giveat least t&o possible statement#

    +) 5et the number o each team &hose captain is someone older than player +1#

    .) ?hat is the result o the ollo&ing S--/$ statement

    S--/$ P37-R46, -35U-46

    FR6% P37-RS

    ?8-R- -35U-46 H -35-46

    / 5et the number o each player &ho has &on a match in at least one team#

    ) Find the number o each player &ho has played at least one match &ith ive sets#

    Con$itions Coup#e$ ith A1D* @"* 1@!

    Q-): 5et the number, name, se! and birth date o each male player born ater C12

    S--/$ P37-R46, 43%-, S-;, BIR$8:D3$-

    FR6% P37-RS

    ?8-R- S-; J %A

    34D BIR$8:D3$- H .+C12A

    Q-4: 5et the numbers, names and places o residence o all players &ho live in

    Plymouth or -ltham '

    S--/$ P37-R46, 43%-, $6?4

    FR6% P37-RS

    ?8-R- $6?4 J PlymouthA

    6R $6?4 J -lthanA

    Q-5:Find the numbers, names, and to&ns o players &ho do not live in Stratord '

    S--/$ P37-R46, 43%-, $6?4

    FR6% P37-RS

    ?8-R- $6?4 GH StratordA

    Q-6: 5ive the number, to&n and date o birth o each player &ho lives in Stratord or

    Database Design 1#= /h21SQ Statement

  • 8/13/2019 Ch07 SQL Statement

    15/26

    saklviTaly ebolR)ay Build Bright University

    &as born in C>., but do not include those &ho live in Stratord and &ere born inC>. '

    S--/$ P37-R46, $6?4, BIR$8:D3$-

    FR6% P37-RS

    ?8-R- ($6?4 J StratordA 6R 7-3R(BIR$8:D3$-) J C>.

    34D 46$ ($6?4 J StratordA 34D 7-3R(BIR$8:D3$-) J C>.

    20ercises:4 5ive the number, the name and to&n o each emale player &ho is not a resident o

    Stratord#

    5 Find the player numbers o those &ho Koined the club bet&een C12 and CE2#

    6 Find the number, name and dates o birth o players born in a leap year# 9 &ho has &on at least one match, give his

    or her name and initials and the divisions o the teams in &hich

    !he Beteen @perator

    Q-7: Find the number and date o birth o each player born bet&een C>+ and C>=

    S--/$ P37-R46, BIR$8:D3$-

    FR6% P37-RS

    ?8-R- BIR$8:D3$- HJ/date (22C>+A)

    34D BIR$8:D3$- GJ /date(.+C>=A)

    $his statement can also be &ritten using the B-$?--4 operator ($he result remains

    the same)#

    S--/$ P37-R46, BIR$8:D3$-

    FR6% P37-R

    ?8-R- BIR$8:D3$- HJ/date(22C>+A)34D /date(.+CA)

    Q;:5ive the numbers o the matches &here the sum o the number o sets &on and

    lost is eNual to +, . or = '

    Database Design 1#9 /h21SQ Statement

  • 8/13/2019 Ch07 SQL Statement

    16/26

    saklviTaly ebolR)ay Build Bright University

    S--/$ %3$/846, ?64 O 6S$

    FR6% %3$/8S

    ?8-R- ?64 O 6S$ B-$?--4 + 34D =

    20ercises:

    2) 5et the payment number o each penalty bet&een 92M and 22M

    ) 5et the payment number o each penalty that is not bet&een 92M and 22M

    +) 5ive the numbers o the players &ho Koined the club ater the age o > and beore

    reaching =2 (?e remind you that

    Q, :Find the number, name and to&n o each player &ho lives in Ingle&ood,

    Plymouth, %idhurst or Douglas '

    S--/$ P37-R46, 43%-, $6?4

    FR6% P37-RS

    ?8-R- $6?4 J Ingle&oodA 6R $6?4 J PlymouthA

    6R $6?4 J %odhurstA 6R $6?4 J 5ouglasA

    !he I1 operator can be use$ to simp#ify the statement'

    S--/$ P37-R46, 43%-, $6?4

    FR6% P37-RS

    ?8-R- $6?4 I4 ( Ingle&oodA , PlymouthA , %idhurstA, DouglasA

    Q-:5et the number and years o birth o the players born in C>+, C>., C12 '

    S--/$ P37-R46, 43%-, 7-3R(BIR$8:D3$-)

    FR6% P37-RS

    ?8-R- 7-3R(BIR$8:D3$-) I4 (C>+, C>., C12)

    Q: $he I@- operator'Find the name and the number o each player &hose name begins &ith a capital B '

    Database Design 1#> /h21SQ Statement

  • 8/13/2019 Ch07 SQL Statement

    17/26

    saklviTaly ebolR)ay Build Bright University

    S--/$ 43%-, P37-R46

    FR6% P37-RS

    ?8-R- 43%- I@- BLA

    Q/:5et the name and the number o each player &hose name ends &ith the small

    letter r '

    S--/$ 43%-, P37-R46

    FR6% P37-RS

    ?8-R- 43%- I@- LrA

    !he IS 13LL operator:

    Q):5et the name, the number and the league number o each player &hose league

    number is not eNual to E=>1 '

    S--/$ 43%-, P37-R46, -35U-46

    FR6% P37-RS

    ?8-R- -35U-46 GH E=>1

    6R -35U-46 IS 4U

    !he I1 operator ith sub=uery:

    Q4: 5et all inormation about each player &hose player number is eNual(==, +, 91, +1, 2=, +, >, E., E)

    S--/$ LFR6% P37-RS

    ?8-R- P37-R46 I4 (==, +, 91, +1, 2=, +)

    Q5: 5ive the result o this statement'

    S--/$ P37-R46, 43%-, I4I$I3S

    FR6% P37-RS

    ?8-R- P37-R46 I4 ( S--/$ P37-R46

    FR6% %3$/8-S )

    Database Design 1#1 /h21SQ Statement

  • 8/13/2019 Ch07 SQL Statement

    18/26

    saklviTaly ebolR)ay Build Bright University

    Q6: 5et the Player46, 4ame, and $o&n o each player &ho has played at least one

    match or the irst team '

    S--/$ P37-R46, 43%-, $6?4

    FR6% P37-RS

    ?8-R- P37-R46 I4 ( S--/$ P37-R46

    FR6% %3$/8-S

    ?8-R- $-3%46 J )

    Q7: 5ive the Player4o, 4ame and $o&n o each player &ho has played at least one

    match or a team that is not captained by player > '

    S--/$ P37-R46, 43%-

    FR6% P37-RS

    ?8-R- P37-R46 I4 ( S--/$ P37-R46

    FR6% %3$/8-S

    ?8-R- $-3%46 46$ I4

    ( S--/$ $-3%46

    FR6% $-3%S

    ?8-R- P37-R46 J > ))

    Q/;: Find the number and name o the player &ho captains team '

    S--/$ P37-R46, 43%-

    FR6% P37-RS

    ?8-R- P37-R46 J ( S--/$ P37-R46

    FR6% $-3%S

    ?8-R- $-3%46 J )

    Q/,:Find the player number, name, and initials o each player &ho is older than

    Database Design 1#E /h21SQ Statement

  • 8/13/2019 Ch07 SQL Statement

    19/26

    saklviTaly ebolR)ay Build Bright University

    R#Parmenter '

    S--/$ P37-R46, 43%-, I4I$I3S

    FR6% P37-RS

    ?8-R- BIR$8:D3$- G ( S--/$ BIR$8:D3$-

    FR6% P37-RS

    ?8-R- 43%- J ParmenterA

    34D I4I$I3S J RA )

    Q/-: Find the player number, date o birth and the name and initials o each player

    &hose birth date is bet&een those o B#4e&castle and P#%iller '

    S--/$ P37-R46, BIR$8:D3$-, 43%-, I4I$I3S

    FR6% P37-RS

    ?8-R- BIR$8:D3$- B-$?--4

    ( S--/$ BIR$8:D3$- FR6% P37-RS

    ?8-R- 43%- J 4e&castleA 34D I4I$I3S J BA )

    34D ( S--/$ BIR$8:D3$- FR6% P37-RS?8-R- 43%- J %illerA 34D I4I$I3S J PA )

    Q/:5et the names and initials o players &ho have incurred at least one penalty '

    S--/$ 43%-, I4I$I3S

    FR6% P37-RS

    ?8-R- P37-R46 I4 ( S--/$ P37-R46

    FR6% P-43$I-S )

    Q//:5et the names and initials o the players &ho are not team captains '

    S--/$ 43%-, I4I$I3S

    Database Design 1#C /h21SQ Statement

  • 8/13/2019 Ch07 SQL Statement

    20/26

    saklviTaly ebolR)ay Build Bright University

    FR6% P37-RS

    ?8-R- 46$ -;IS$S (S--/$ L

    FR6% $-3%S ?8-R- P37-R46 J Players.Player46

    Q/): 5ive the player numbers, names and the dates o birth o the oldest players# $he

    oldest players are those &hose date o birth is less than or eNual to that o every other

    player'

    S--/$ P37-R46, 43%-, BIR$8:D3$-

    FR6% P37-RS

    ?8-R- BIR$8:D3$- G J 3 ( S--/$ BIR$8:D3$-

    FR6% P37-RS )

    Q/4:For each team ind the team number and the number o the player &ith the

    lo&est number o sets &on '

    S--/$ DIS$I4/$ $-3%46, P37-R46

    FR6% %3$/8-S 3S %

    ?8-R- ?64 GJ 3 ( S--/$ ?64

    FR6% %3$/8-S 3S %+ ?8-R- %#$-3%46 J %+#$-3%46 )

    Q/5:5et the player number, name and dates o birth o players e!cept the oldest '

    S--/$ P37-R46, 43%-, BIR$8:D3$-FR6% P37-RS

    ?8-R- BIR$8:D3$- H 347 ( S--/$ BIR$8:D3$-

    FR6% P37-RS )

    Q/6 : Find all the dierent to&n names in the P37-RS table'

    S--/$ DIS$I4/$ $6?4

    FR6% P37-RS

    Database Design 1#+2 /h21SQ Statement

  • 8/13/2019 Ch07 SQL Statement

    21/26

    saklviTaly ebolR)ay Build Bright University

    >I. An Intro$uction to set functions :

    /6U4$

    %I4

    %3;

    SU%

    305

    Q/7:8o& many player in the P37-RS table are registered

    S--/$ /6U4$(L)

    FR6% P37-RS

    Q);:8o& many players live in StratordT

    S--/$ /6U4$ (L) 3S /6U4$

    FR6% P37-RS

    ?8-R- $6?4 J StratordA

    Q),:%3; and %I4 unctionsT

    ?hat is the highest and lo&est penalty'

    S--/$ %I4(3%6U4$) 3S %I4, %3;(3%6U4$) 3S %3;

    FR6% P-43$I-S

    Q)-:?hat is the lo&est penalty incurred by a player resident in StratordT

    S--/$ %I4 (3%6U4$)

    FR6% P-43$I-S

    ?8-R- P37-R46 I4 ( S--/$ P37-R46

    FR6% P37-RS

    ?8-R- $6?4 J StratordA

    Database Design 1#+ /h21SQ Statement

  • 8/13/2019 Ch07 SQL Statement

    22/26

    saklviTaly ebolR)ay Build Bright University

    !he S3

  • 8/13/2019 Ch07 SQL Statement

    23/26

  • 8/13/2019 Ch07 SQL Statement

    24/26

    saklviTaly ebolR)ay Build Bright University

    S--/$ P37-R46, P37%-4$46,43%- 3scending 3S/

    FR6% P37-RS Descending D-S/

    6RD-R B7 43%- D-S/

    Q4: 5ive all penalties sorted by year, and &ithin each year by payment number

    S--/$ P37%-4$:D3$-, P37%-4$46

    FR6% P-43$I-S

    6RD-R B7 7-3R ( P37%-4$:D3$- ), P37%-4$46

    Combining ith 31I@1

    Q4/: 5ive the player number and place o residence o each player rom Ingle&ood

    and Plymouth '

    S--/$ P37-R46, $6?4

    FR6% P37-RS

    ?8-R- $6?4 J Ingle&oodA

    U4I64

    S--/$ P37-R46, $6?4

    FR6% P37-RS

    ?8-R- $6?4 J PlymouthA

    rebobTI -

    S--/$ P37-R46, $6?4

    FR6% P37-RS

    ?8-R- $6?4 J Ingle&oodA 6R $o&n J PlymouthA

    !he Sub=uery

    Q4):5et the number and division o each team in &hich player == has played

    Database Design 1#+= /h21SQ Statement

  • 8/13/2019 Ch07 SQL Statement

    25/26

    saklviTaly ebolR)ay Build Bright University

    S--/$ $-3%46, DI0ISI64

    FR6% $-3%S

    ?8-R- -;IS$S ( S--/$ L

    FR6% %3$/8-S

    ?8-R- Player46 J ==

    34D $-3%46 J $-3%S#$-3%46

    Q44:5et the player number o each player &ho has incurred more than one penalty'

    S--/$ DIS$I4/$ P37-R46

    FR6% P-43$I-S 3S P

    ?8-R- P37-R46 I4

    ( S--/$ P37-R46 FR6% P-43$I-S 3S P+ ?8-R- P+#Payment46GHP#Payment46

    Q45: 5ive the number and the name o each player &ho has not played matches or

    team

    S--/$ P37-R46, 43%-

    FR6% P37-RS

    ?8-R- GH 3 ( S--/$ $-3%46

    FR6% %3$/8-S

    ?8-R- Player46 J players#player46 )

    Q46:5ive the player number o each player &ho has played or the same teams as

    player 91

    S--/$ P37-R46

    FR6% %3$/8-S

    ?8-R- $-3%46 I4

    ( S--/$ $-3%46

    FR6% $-3%S

    ?8-R- $-3%46 I4

    ( S--/$ $-3%46

    FR6% %3$/8-S

    ?8-R- P37-R46 J 91 ) )

    Database Design 1#+9 /h21SQ Statement

  • 8/13/2019 Ch07 SQL Statement

    26/26

    saklviTaly ebolR)ay Build Bright University

    oin in the