【发布时间】:2015-06-29 21:42:53
【问题描述】:
我对第二个问题有疑问,因为我收到错误“当子查询没有与 EXISTS 一起引入时,选择列表中只能指定一个表达式。”。你能帮帮我吗?
Select P.Name, P.ProductCategoryID, PC.Name, Max(P.ListPrice) as MaxPrice
from SalesLT.Product as P
join SalesLT.ProductCategory as PC
on PC.ProductCategoryID=P.ProductCategoryID
where P.ListPrice=
(select Max(ListPrice)
from SalesLT.Product as P2
where P2.ProductCategoryID=P.ProductCategoryID)
group by P.Name, P.ProductCategoryID, PC.Name
order by MaxPrice desc;
go
with sale_cte as
(Select PC.Name, P.ProductCategoryID, P.Listprice,
ROW_NUMBER() over(partition by PC.Name order by P.Listprice) as RN
from SalesLT.Product as P
join SalesLT.ProductCategory as PC
on PC.ProductCategoryID=P.ProductCategoryID)
Select PC.Name,
(select *
from sale_cte)
from SalesLT.ProductCategory as PC
wher RN=1
【问题讨论】:
-
投反对票原因:阅读错误信息。
标签: sql sql-server