拜托姐夫别乱来,snb,cf灵狐者裙底吧
1 declare @t table( 2 ProductID int, 3 ProductName varchar(20), 4 ProductType varchar(20), 5 Price int) 6 7 insert @t 8 select 1,'name1','P1',3 union all 9 select 2,'name2','P1',5 union all 10 select 3,'name3','P2',4 union all 11 select 4,'name4','P2',4
select t1.* from @t t1 join (select ProductType, max(Price) Price from @t group by ProductType) t2 on t1.ProductType = t2.ProductType where t1.Price = t2.Price order by ProductType
;with cte as(select *, max(Price) over(partition by (ProductType)) MaxPrice from @t) select ProductID,ProductName,ProductType,Price from cte where Price = MaxPrice order by ProductType
;WITH OrderInfo AS ( SELECT ROW_NUMBER() OVER(PARTITION BY EmployeeID ORDER BY OrderDate) AS Number, OrderID,CustomerID, EmployeeID,OrderDate FROM Orders (NOLOCK) ) SELECT Number,OrderID,CustomerID, EmployeeID ,OrderDate From OrderInfo WHERE Number BETWEEN 0 AND 10
WITH OrderInfo AS ( SELECT COUNT(OrderID) OVER(PARTITION BY EmployeeID) AS TotalCount,OrderID,CustomerID, EmployeeID,OrderDate FROM Orders (NOLOCK) ) SELECT OrderID,CustomerID, EmployeeID ,OrderDate,TotalCount From OrderInfo ORDER BY EmployeeID
WITH OrderInfo AS ( SELECT COUNT(OrderID) OVER() AS Count,OrderID,CustomerID, EmployeeID,OrderDate FROM Orders (NOLOCK) )
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
数据库SQL---数据库、基本表、视图、索引的定义、修改、删除
在 Azure CentOS VM 中配置 SQL Server 2019 AG - (上)
在 Azure CentOS VM 中配置 SQL Server 2019 AG - (下)
网友评论