Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 7

Ryan International School SQL Practice Questions Holiday Homework Class XII Assignment 1 Consider the following table

definitions: ranch Staff !branch"o# street# city# $ostcode% !staff"o# f"ame#l"ame# $osition# se&# '( # salary# branch"o% staff"o# branch"o% Client +iewing Registration !client"o# f"ame# l"ame# tel"o# $ref)y$e# ma&Rent% !client"o# $ro$erty"o# *iew'ate# comment% !client"o# branch"o# staff"o# date,oined% Pri*ate(wner !owner"o# f"ame# l"ame# address# tel"o%

Pro$ertyforRent !$ro$erty"o# street# city# $ostcode# ty$e# rooms# rent# owner"o#

Com$lete the SQL Statements for the -ollowing: ./ List the address of all branch offices in London or ristol/ 0/ List the staff with a salary between 1.2222 and 132222/ 3/ List the staff in descending order of salary/ 4/ -ind the number of different $ro$erties *iewed in 5$ril 0224/ 6/ -ind the minimum# ma&imum and a*erage staff salary/ 7/ -or each branch office with more than one member of staff# find the number of staff working in each branch and the sum of their salaries/ 8/ List the staff who work in the branch whose stree adress is 9.73 :ain Street; </ -ind all staff whose salary is larger than the salary of e*ery staff member at branch with branch"o 223/

=/ -or each branch# list the numbers and names of staff who manage $ro$erties# including the city in which the branch is located and the $ro$erties that the staff manage/ .2/ List the clients who ha*e *iewed a $ro$erty/ ../ -ind the list of all cities where there is both a branch office and a $ro$erty .0/ >i*e all managers 6? increase to their salary .3/ 'elete all *iewings that belong to $ro$erty with $ro$erty number P>4/

5ssignment @ II >i*en the following table definitions: message !messageAid# subBect# body% sentAto!messageAid# email# senddate% customer !email# name# familyAsiCe# address% -or each case below# fill in the blanks such that the SQL Dueries corres$ond to the English language Dueries stated/ .F -ind the names and emails of all customers who ha*e sent the message with subBect GHa$$y "ew HearI select Acustomer.email, nameAAA from message# sentAto# customer where Asubject=Happy New Year AND message.message i!=sent to.message i! AND sent to.email=customer.email 0F -ind the names and common addresses of all $airs of customers who claim to ha*e a famlily siCe 0 and and ha*e the same address/ select C./name# A"#.name where c1.name$%c#.name # C./address A 5"'# Ac1.family si&e=# AAAAA 5"'

from Acustomer "1, customer "# C0/familyAsiCeJ0 5"' c1.a!!ress=c#.a!!ressAAA 3F -ind the names of all customers and their family siCe whose family siCe is at least 62? more than the a*erage family siCe/ Sort the results by family siCe/

create 'iew a*erageAsiCe !asiCe% as select Aa'g(family si&e) AAAAA from Acustomer AAAAAAA

select name# familyAsiCe

from Acustomer

AAAAAAa*erageAsiCe

where Afamily si&e %= 1.*+ a si&e or!er by family si&e 4F -ind all customers each ha*ing a family siCe different from the total number of customers ha*ing the same address as him or her/ create 'iew addressAandAcount !address# count% select address# count K from Acustomer group by a!!ress select C/name fromAcustomer ", a!!ress an! count A where C/addressJ5/address 5"' family si&e$%count AAA AAAAAAAAAAAA

5ssignment F III Consider the following relation table for an airline database/ customer(i!, name, age, gen!er) on,light(i!, flightNo, flightDate) flight-nfo(flightNo, from"ity, to"ity, start.ime, !uration) ./ "ames of all customers abo*e the age of .2 SELEC) AAAAAAAAAAAAAAAname -R(: customer LHERE AAAAAAAAAAAAAAAA ageM.2

0/ -lights !flight"o# flight'ate% on which there are at least two customers SELEC) f./flight"o# f./flight'ate -R(: on-light as f.# on-light as f0 LHERE f./flight"o J f0/flight"o 5"' f./flight'ateJf0/flight'ate 5"' AAAAAAAAAAAAAAAAAA f./id NM f0/id

3/ -lights !flight"o# flight'ate% on which there are at least two customers# as well as the number of $assengers on the flights SELEC) flight"o# flight'ate# count!id% as how:any -R(: on-light >R(OP H AAAAAAAAAAAAAAAAAAAAA flight"o# flight'ate H5+I"> AAAAAAAAAAAAAAAAAAAAA how:anyM.

4/ "ames of $assengers who flew on flight G)P.20I at least once SELEC) name -R(: customer# on-light LHERE AAAAAAAAAAAAAAAAAAAA customer/idJon-light/id 5"'

AAAAAAAAAAAAAAAAAAAA on-light/flight"oJI)P.20I

6/ "ames of customers who ne*er flew on any flight SELEC) name -R(: customer AAAAAAAAAAAAAAAAAAAA left outer Boin flight LHERE AAAAAAAAAAAAAAA flight"o J "OLL

7/ "ames of customers who flew on the same flight as :r/ ,oe LI)H Boe-light!flight"o% 5S SELEC) flight"o -R(: AAAAAAAAAAAAAAAAAAAcustomer natural inner Boin on-light LHERE name J G,oeI SELEC) name -R(: customer# on-light# Boe-light LHERE AAAAAAAAAAAAAAAAAAA customer/id J on-light/id 5"'

AAAAAAAAAAAAAAAAAAAAAAA on-light/flight"o J Boe-light/flight"o

8/ )he number of $assengers on flight G)P.2.I on G.Q0Q.===I SELEC) AAAAAAAAAAAAAAAAA count!id % -R(: on-light LHERE flight"oJ G)P.2.I 5"' flight'ateJG.Q0Q.===I

</ )he most $o$ular destination !i/e/ the city which recei*ed the most number of tra*ellers% LI)H cityAtourists!toCity#How:any% 5S SELEC) toCity# count!K% -R(: on-light natural inner Boin flightInfo >R(OP H toCity LI)H most)ourist!How:any% 5S SELEC) AAAAAAAAAAAAAAAAAAA ma&!How:any% -R(: AAAAAAAAAAAAAAAAAAA cityAtourists SELEC) toCity -R(: AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA cityAtourists# most)ourist LHERE AAAAAAAAAAAAAAAAAAAAAAAAAAAAA cityAtourists/How:any J

most)ourist/How:any

=/ How many $assengers e*er flew to IstanbulR If somebody tra*elled to Istanbul more than one time# only one of those *isits should be counted/ SELEC) AAAAAAAAAAAAAAAAAAAcount !distinct id% -R(: on-light natural inner Boin flightInfo LHERE toAcity J GIstanbulI

You might also like