[英]SQL not a single-group group function calculation
Select CATEGORY, TITLE, RETAIL
From BOOKS
Where RETAIL = ( SELECT RETAIL-max(COST) From Books)
ORDER BY Category ASC;
What I'm trying to achieve is to show the retail prices which are less than the MAX cost of all the books 我要达到的目的是要显示低于所有书籍的最高成本的零售价格
Example 例
MAX COST = $44
Display number of retail items that are LESS than $44
CREATE TABLE TBL_BOOKS_PRICE
(
BOOK VARCHAR(24),
PRICE MONEY
)
GO
INSERT INTO TBL_BOOKS_PRICE
VALUES('BOOK1',33.00)
GO
INSERT INTO TBL_BOOKS_PRICE
VALUES('BOOK1',44.00)
GO
INSERT INTO TBL_BOOKS_PRICE
VALUES('BOOK1',43.00)
GO
INSERT INTO TBL_BOOKS_PRICE
VALUES('BOOK1',38.00)
GO
SELECT BOOK,PRICE FROM
(
SELECT ROW_NUMBER() OVER (ORDER BY PRICE DESC) ID,* FROM TBL_BOOKS_PRICE
) A
WHERE ID<>1;
Try this.. 尝试这个..
with tmp as (
select category, title, retail, max(cost) as retail_max_cost
from books group by category, title, retail)
select category, title, retail from tmp
where retail < retail_max_cost order by category;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.