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
Do'stlaringiz bilan baham: |