Шпоры к ГОСу по базам данных - файл n1.doc

приобрести
Шпоры к ГОСу по базам данных
скачать (15.2 kb.)
Доступные файлы (1):
n1.doc92kb.28.05.2005 15:11скачать

n1.doc

Базы данных

База данных содержит таблицы:

s – поставщики p - товары sp - поставки

s_no sname status city p_no pname color city s_no p_no qty | s_no p_no qty

s1 Smith 20 London p1 Nut Red London s1 p1 300 | s2 p1 300

s2 Jones 10 Paris p2 Bolt Green Paris s1 p2 200 | s2 p2 400

s3 Blake 30 Paris p3 Screw Blue Rome s1 p3 400 | s3 p2 200

s4 Clark 20 London p4 Screw Red London s1 p4 200 | s4 p2 200

s5 Adams 30 Athens p5 Cam Blue Paris s1 p5 100 | s4 p4 300

p6 Cog Red London s1 p6 100 | s4 p5 400

Какие (может быть несколько или ни одного!) из ниже перечисленных операторов SELECT дают следующую выборку:
1) Выборка: s_no sname city

s1 Smith London

s5 Adams Athens

Варианты:

Д) SELECT s_no, sname,city FROM s WHERE city LIKE '%th%' OR sname LIKE '%th%'
2) Выборка: s_no sname

s1 Smith

s4 Clark

Варианты:

Б) SELECT s_no,sname FROM s WHERE NOT EXISTS (SELECT * FROM p WHERE city='Paris'

AND p_no NOT IN (SELECT p_no FROM sp WHERE s.s_no=sp.s_no))

Г) SELECT s_no,sname FROM s WHERE NOT EXISTS (SELECT * FROM p WHERE city='Paris'

AND NOT EXISTS (SELECT * FROM sp WHERE p.p_no=sp.p_no AND s.s_no=sp.s_no))
3) Выборка: s_no sname sum_p

s1 Smith 1300

Варианты:

В) SELECT s.s_no,sname,SUM(qty) AS sum_p FROM s,sp WHERE s.s_no=sp.s_no

GROUP BY s.s_no,sname HAVING COUNT(*)>3
4) Выборка: s_no sname

s2 Jones

s3 Blake

Варианты:

Г) SELECT s_no,sname FROM s WHERE EXISTS(SELECT s_no FROM sp WHERE s.s_no=sp.s_no GROUP BY s_no HAVING COUNT(*)<3)
5) Выборка: s_no city status p_no qty

s2 Paris 10 p1 300

s2 Paris 10 p2 400

s4 London 20 p2 200

s1 London 20 p4 200

s1 London 20 p2 200

s4 London 20 p4 300

s1 London 20 p1 300

s4 London 20 p5 400

s1 London 20 p3 400

s3 Paris 30 p2 200

Варианты:

Д) SELECT s.s_no,city,status,p_no,qty FROM s,sp WHERE s.s_no=sp.s_no AND qty>100

ORDER BY status,city DESC,qty
6) Выборка: s_no sname

s1 Smith

s3 Blake

s4 Clark

Варианты:

А) SELECT s_no, sname FROM s WHERE s_no<>'s2' AND s_no IN (SELECT s_no FROM sp

WHERE p_no IN (SELECT p_no FROM sp WHERE s_no='s2'))

Д) SELECT DISTINCT s.s_no, sname FROM s,sp x,sp y WHERE s.s_no<>'s2'

AND s.s_no=x.s_no AND x.p_no=y.p_no AND y.s_no='s2'
7) Выборка: p_no pname

p2 Bolt

p5 Cam

p6 Cog

Варианты:

А) SELECT p_no,pname FROM p WHERE p_no IN (SELECT p_no FROM sp WHERE qty<200)

OR p_no IN (SELECT p_no FROM sp WHERE s_no='s3')

Д) SELECT p_no,pname FROM p WHERE p_no IN (SELECT p_no FROM sp WHERE qty<200)

OR EXISTS (SELECT * FROM sp WHERE s_no='s3' AND sp.p_no=p.p_no)
8) Выборка: s_no city status p_no qty

s2 Paris 10 p2 400

s2 Paris 10 p1 300

s4 London 20 p5 400

s1 London 20 p3 400

s4 London 20 p4 300

s1 London 20 p1 300

s4 London 20 p2 200

s1 London 20 p4 200

s1 London 20 p2 200

s3 Paris 30 p2 200

Варианты:

А) SELECT s.s_no,city,status,p_no,qty FROM s,sp WHERE s.s_no=sp.s_no AND qty>100

ORDER BY status, city DESC, qty DESC

Б) SELECT s.s_no,city,status,p_no,qty FROM s,sp WHERE s.s_no=sp.s_no AND qty>100

ORDER BY status ASC, city DESC, qty DESC
9) Выборка: s_no sname p_no qty

s1 Smith p6 100

s1 Smith p5 100

s5 Adams null null

Варианты:

Б) SELECT s.s_no,sname,p_no,qty FROM s,sp WHERE s.s_no=sp.s_no AND qty<200 UNION

SELECT s_no,sname, NULL AS p_no, NULL AS qty FROM s

WHERE s_no NOT IN (SELECT s_no FROM sp)

В) SELECT s.s_no,sname,p_no,qty FROM s LEFT JOIN sp ON (s.s_no=sp.s_no)

WHERE qty IS NULL OR qty<200
10) Выборка: s_no sname

s1 Smith

s2 Jones

s3 Blake

s4 Clark

Варианты:

Г) SELECT s_no,sname FROM s WHERE EXISTS (SELECT * FROM p WHERE city='Paris'

AND EXISTS (SELECT * FROM sp WHERE p.p_no=sp.p_no AND s.s_no=sp.s_no))
11) Выборка: s_no sname

s1 Smith

s3 Blake

s4 Clark

s5 Adams

Варианты:

Г) SELECT DISTINCT s.s_no,sname FROM s LEFT JOIN sp ON (s.s_no=sp.s_no)

WHERE qty IS NULL OR qty=200
12) Выборка: p_no pname

p1 Nut

p2 Bolt

Варианты: Д) SELECT p_no, pname FROM p WHERE p_no IN (SELECT p_no FROM sp

WHERE sp.s_no IN (SELECT s_no FROM s WHERE city='Paris'))
13) Выборка: s_no sname p_no pname qty

s1 Smith p3 Screw 400

s2 Jones p2 Bolt 400

s4 Clark p5 Cam 400

Варианты:

Б) SELECT s.s_no,sname,p.p_no,pname,qty FROM s,sp,p WHERE s.s_no=sp.s_no

AND p.p_no=sp.p_no AND qty>300

Г) SELECT s.s_no,sname,p.p_no,pname,sp.qty FROM s,sp INNER JOIN p ON (sp.p_no=p.p_no)

WHERE qty>300 AND s.s_no=sp.s_no
14) Выборка: s_no sname

s1 Smith

s4 Clark

Варианты:

Б) SELECT s_no,sname FROM s WHERE s_no IN (SELECT s_no FROM sp

GROUP BY s_no HAVING COUNT(*)>2)

В) SELECT s.s_no,sname FROM s,sp WHERE s.s_no=sp.s_no

GROUP BY s.s_no,sname HAVING COUNT(*)>2
15) Выборка: s_no city status p_no qty

s4 London 20 p2 200

s1 London 20 p4 200

s1 London 20 p2 200

s4 London 20 p4 300

s1 London 20 p1 300

s4 London 20 p5 400

s1 London 20 p3 400

s2 Paris 10 p1 300

s2 Paris 10 p2 400

s3 Paris 30 p2 200

Варианты:

Д) SELECT s.s_no,city,status,p_no,qty FROM s,sp WHERE s.s_no=sp.s_no AND qty>100

ORDER BY city,status,qty
16) Выборка: s_no cnt_p

s1 13

Варианты:

Д) SELECT 's1' AS s_no,COUNT(*) AS cnt_p FROM (s LEFT JOIN sp ON (s.s_no=sp.s_no))

LEFT JOIN p ON p.p_no=sp.p_no
17) Выборка: s_no sname

s1 Smith

s2 Jones

s4 Clark

Варианты:

Д) SELECT DISTINCT s.s_no,sname FROM s,sp WHERE s.s_no = sp.s_no AND qty>200
18) Выборка: p_no pname

p2 Bolt

p3 Screw

Варианты:

Д) SELECT DISTINCT p.p_no,p.pname FROM p WHERE city NOT IN ('London')

AND pname NOT IN ('Cam')
19) Выборка: s_no sname

s1 Smith

s2 Jones

s3 Blake

Варианты:

В) SELECT DISTINCT s.s_no, sname FROM (s INNER JOIN sp x ON (s.s_no=x.s_no

AND s.s_no<>'s4')) INNER JOIN sp y ON (x.p_no=y.p_no AND y.s_no='s4')

AND s.s_no<>'s4')) INNER JOIN sp ON (x.p_no=y.p_no AND y.s_no='s4')
20) Выборка: s_no sname city

s3 Blake Paris

s5 Adams Athens

Варианты:

А) SELECT s_no, sname, city FROM s WHERE city LIKE '%a%' AND sname LIKE '%a%'
21) Выборка: s_no sname city

s1 Smith London

s3 Blake Paris

s5 Adams Athens

Варианты:

Д) SELECT s_no, sname, city FROM s WHERE status>20 OR sname LIKE '%th%'
22) Выборка:s_no sname p_no pname qty

s1 Smith p3 Screw 400

s1 Smith p5 Cam 100

s4 Clark p5 Cam 400

Варианты:

Д) SELECT s.s_no,sname,p.p_no,pname,qty FROM s,sp,p WHERE s.s_no=sp.s_no

AND p.p_no=sp.p_no AND status>10 AND color='Blue'
23) Выборка:s_no sname sum_p

s1 Smith 1300

s4 Clark 900

Варианты:

А) SELECT s.s_no,sname,SUM(qty) AS sum_p FROM s,sp WHERE s.s_no=sp.s_no

GROUP BY s.s_no,sname HAVING COUNT(*)>2
24) Выборка: p_no pname

p2 Bolt

Варианты:

Б) SELECT p_no,pname FROM p WHERE EXISTS (SELECT * FROM sp WHERE p.p_no=sp.p_no

AND EXISTS (SELECT * FROM s WHERE sp.s_no=s.s_no AND status>20))
25) Выборка: s_no sname

s2 Jones

s3 Blake

s5 Adams

Варианты: среди вариантов нет правильного ответа

А) SELECT s_no,sname FROM s WHERE NOT EXISTS (SELECT * FROM p WHERE city='Paris'

AND NOT EXISTS (SELECT * FROM sp WHERE p.p_no=sp.p_no AND s.s_no=sp.s_no))

Б) SELECT s_no,sname FROM s WHERE EXISTS (SELECT * FROM p WHERE city='Paris'

AND NOT EXISTS (SELECT * FROM sp WHERE p.p_no=sp.p_no AND s.s_no=sp.s_no))

В) SELECT s_no,sname FROM s WHERE EXISTS (SELECT * FROM p WHERE city='Paris'

AND EXISTS (SELECT * FROM sp WHERE p.p_no=sp.p_no AND s.s_no=sp.s_no))

Г) SELECT s_no,sname FROM s WHERE EXISTS (SELECT * FROM p WHERE city='Paris'

AND (SELECT * FROM sp WHERE p.p_no=sp.p_no AND s.s_no=sp.s_no))

Д) SELECT s_no,sname FROM s WHERE NOT EXISTS (SELECT * FROM p WHERE city='Paris'

AND p_no NOT IN (SELECT p_no FROM sp WHERE s.s_no=sp.s_no))
26) Выборка: s_no sname

s1 Smith

s2 Jones

s4 Clark

Варианты:

Г) SELECT DISTINCT s.s_no, sname FROM (s INNER JOIN sp x ON (s.s_no=x.s_no

AND s.s_no<>'s3')) INNER JOIN sp y ON (x.p_no=y.p_no AND y.s_no='s3')

27) Выборка: s_no sname sum_p

s1 Smith 1300

s2 Jones 700

s4 Clark 900

Варианты:

В) SELECT s.s_no,sname,SUM(qty) AS sum_p FROM s,sp WHERE s.s_no=sp.s_no

AND EXISTS(SELECT * FROM sp z WHERE sp.s_no=z.s_no AND sp.p_no<>z.p_no)

GROUP BY s.s_no,sname

Д) SELECT s.s_no,sname,SUM(qty) AS sum_p FROM s,sp WHERE s.s_no=sp.s_no

GROUP BY s.s_no,sname HAVING COUNT(*)>1
28) Выборка: p_no pname

p3 Screw

p5 Cam

Варианты:

Д) SELECT DISTINCT p.p_no,p.pname FROM sp,p WHERE sp.p_no=p.p_no

AND color IN ('Black','Blue','White')
29) Выборка: s_no sname

s1 Smith

s2 Jones

s4 Clark

Варианты:

А) SELECT s.s_no,sname FROM s,sp WHERE s.s_no=sp.s_no

GROUP BY s.s_no,sname HAVING COUNT(*)>=2
30) Выборка: s_no cnt_p

s1 12

Варианты:

А) SELECT 's1' AS s_no,COUNT(pname) AS cnt_p FROM (s LEFT JOIN sp

ON (s.s_no=sp.s_no)) LEFT JOIN p ON p.p_no=sp.p_no
31) Выборка: s_no sname p_no pname qty

s1 Smith p1 Nut 300

s1 Smith p4 Screw 200

s1 Smith p6 Cog 100

s4 Clark p4 Screw 300

Варианты:

Б) SELECT s.s_no,sname,p.p_no,pname,qty FROM (s INNER JOIN sp ON s.s_no=sp.s_no)

INNER JOIN p ON sp.p_no=p.p_no WHERE status>10 AND color='Red'
32) Выборка: p_no pname

p2 Bolt

p3 Screw

p5 Cam

Варианты:

Г) SELECT DISTINCT p.p_no,p.pname FROM p WHERE p_no BETWEEN 'p1'

AND 'p6' AND city NOT IN ('London')

Д) SELECT DISTINCT p.p_no,p.pname FROM sp,p WHERE sp.p_no=p.p_no AND qty>300
33) Выборка: s_no sname p_no qty

s1 Smith p5 100

s1 Smith p6 100

Варианты:

Д) SELECT s.s_no,sname,p_no,qty FROM s RIGHT JOIN sp ON s.s_no=sp.s_no

WHERE qty IS NULL OR qty<200
34) Выборка: s_no sname

s3 Blake

s5 Adams

Варианты:

А) SELECT s_no,sname FROM s WHERE s_no NOT IN (SELECT s_no FROM sp WHERE qty>200)

Б) SELECT s_no,sname FROM s WHERE NOT EXISTS

(SELECT * FROM sp WHERE s.s_no=sp.s_no AND qty>200)
35) Выборка: s_no cnt_p

s1 2

s2 2

s4 2

Варианты:

А) SELECT s_no,COUNT(*) AS cnt_p FROM p,sp WHERE p.p_no=sp.p_no AND qty>200

GROUP BY sp.s_no

Б) SELECT s_no,COUNT(DISTINCT pname) AS cnt_p FROM p INNER JOIN sp ON p.p_no=sp.p_no

WHERE qty>200 GROUP BY sp.s_no
36) Выборка: s_no sname p_no qty

s1 Smith p6 100

Варианты:

Г) SELECT s.s_no,sname,p_no,qty FROM s INNER JOIN sp ON s.s_no=sp.s_no

AND (qty IS NULL OR qty<200) WHERE p_no <> 'p5'

Учебный материал
© nashaucheba.ru
При копировании укажите ссылку.
обратиться к администрации