Select CATEGORY, TITLE, RETAIL
From BOOKS
Where RETAIL = ( SELECT RETAIL-max(COST) From Books)
ORDER BY Category ASC;
我想要实现的是显示零售价低于所有书籍的 MAX 成本
例子
MAX COST = $44
Display number of retail items that are LESS than $44
Select CATEGORY, TITLE, RETAIL
From BOOKS
Where RETAIL = ( SELECT RETAIL-max(COST) From Books)
ORDER BY Category ASC;
我想要实现的是显示零售价低于所有书籍的 MAX 成本
例子
MAX COST = $44
Display number of retail items that are LESS than $44
尝试这个..
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;
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;