/*
RiCo技術學院
微軟SQL Server 2022基礎資料庫設計和開發
   TOP
*/

--回傳前10筆資料 
SELECT TOP (10) [BusinessEntityID]
      ,[PhoneNumber]
      ,[PhoneNumberTypeID]
      ,[ModifiedDate]
  FROM [Person].[PersonPhone]
order by [BusinessEntityID]
  
--回傳前6%資料
SELECT TOP(6)PERCENT      
      [BusinessEntityID]
      ,[PhoneNumber]
      ,[PhoneNumberTypeID]
FROM [Person].[PersonPhone]  
order by [BusinessEntityID] 


--WITH TIES 包含符合最後一筆資料的資料
SELECT TOP(6) PERCENT WITH TIES  
pp.FirstName, pp.LastName, e.JobTitle, e.Gender, r.Rate  
FROM Person.Person AS pp   
    INNER JOIN HumanResources.Employee AS e  
        ON pp.BusinessEntityID = e.BusinessEntityID  
    INNER JOIN HumanResources.EmployeePayHistory AS r  
        ON r.BusinessEntityID = e.BusinessEntityID  
ORDER BY Rate DESC;  


--作業
--從[Production].[Product]依據SellStartDate反向排序並回傳前10%資料
SELECT top(10) percent *
FROM [Production].[Product]
order by [SellStartDate] desc
