3. 查询非吉林出版社出版的图书中比吉林出版社任意一个图书册数都少的图书名称和册数。(分别用ANY谓词和聚集函数实现)
时间: 2024-05-21 21:10:28 浏览: 67
图书查询功能的实现
使用ANY谓词:
SELECT b.title, COUNT(*) AS num
FROM books b
WHERE b.publisher <> '吉林出版社' AND
b.num_of_copies < ANY (SELECT b2.num_of_copies
FROM books b2
WHERE b2.publisher = '吉林出版社')
GROUP BY b.title
ORDER BY num;
使用聚集函数:
SELECT b.title, COUNT(*) AS num
FROM books b
WHERE b.publisher <> '吉林出版社'
GROUP BY b.title
HAVING COUNT(*) < MAX(CASE WHEN b.publisher = '吉林出版社' THEN b.num_of_copies ELSE 0 END)
ORDER BY num;
阅读全文