Мартин грубер понимание sql перевод Лебедева В. Н. Под редакцией Булычева В. Н. Москва, 1993 martin gruber


SELECT * FROM Salespeople WHERE NOT city = ANY (SELECT city FROM Customers)


Download 1.45 Mb.
bet150/172
Sana26.01.2023
Hajmi1.45 Mb.
#1128343
1   ...   146   147   148   149   150   151   152   153   ...   172
Bog'liq
Грубер. Понимание SQL

SELECT *
FROM Salespeople
WHERE NOT city = ANY (SELECT city
FROM Customers);



SELECT *
FROM Orders
WHERE amt > ALL (SELECT amt
FROM Orders a, Customers b
WHERE a.cnum = b.cnum AND b.city = 'London');



SELECT *
FROM Orders
WHERE amt > (SELECT MAX (amt)
FROM Orders a, Customers b
WHERE a.cnum = b.cnum AND b.city = 'London');

Глава 14


SELECT cname, city, rating, 'High Rating'
FROM Customers
WHERE rating >= 200

UNION


SELECT cname, city, rating, ' Low Ratlng'
FROM Customers
WHERE rating < 200;

или
SELECT cname, city, rating, 'High Rating'
FROM Customers
WHERE rating >= 200

UNION


SELECT cname, city, rating, ' Low Rating'
FROM Customers
WHERE NOT rating >= 200;

Различие между этими двумя предложениями — в форме второго предиката. Обратите внимание, что в обоих случаях строка "Low Rating" имеет в начале дополнительный пробел для того, чтобы совпадать со строкой "High Rating" по длине.




SELECT cnum, cname
FROM Customers a
WHERE 1 < (SELECT COUNT (*)
FROM Orders b
WHERE a.cnum = b.cnum)

UNION


SELECT snum, sname
FROM Salespeople a
WHERE 1 < (SELECT COUNT (*)
FROM Orders b
WHERE a.snum = b.snum)

ORDER BY 2;




SELECT snum
FROM Salespeople
WHERE city = 'San Jose'

UNION


(SELECT cnum
FROM Customers
WHERE city = 'San Jose'

UNION ALL



SELECT onum
FROM Orders
WHERE odate = 10/03/1990);

Глава 15



Download 1.45 Mb.

Do'stlaringiz bilan baham:
1   ...   146   147   148   149   150   151   152   153   ...   172




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling