-1

试图制作一张表格,其中单本书的成本高于所有书籍的平均成本

SELECT book_num, book_title, book_cost
FROM (SELECT book_num, book_title, book_cost, Avg(book_cost) AS AVGPRICE
      FROM book
      GROUP BY book_num, book_title, book_cost)
WHERE book_cost > AVGPRICE
ORDER BY book_title;
4

2 回答 2

2
SELECT book_num, book_title, book_cost
FROM book
WHERE book_cost > (SELECT  Avg(book_cost) FROM book)
ORDER BY book_title;
于 2013-11-08T02:34:35.840 回答
0

试试这个(我使用了无处不在的 pubs 数据库)

DECLARE @avgprice money;

SET @avgprice = (SELECT  Avg(price) FROM titles);   

SELECT title, price, @avgprice as AveragePrice 
FROM titles 
WHERE price > @avgprice ORDER BY title;
于 2013-11-08T02:30:46.050 回答