取得用於 ADO.NET 程式代碼範例的 SQL Server 資料庫 - ADO.NET | Microsoft Learn因為拿到的題目不是我寫的,所以不放哈哈練習答案沒有用AI,可能會錯--
select * from Products;--
select * from Products order by ProductName;--
select ProductID, ProductName, UnitPrice from Products;--select ProductID AS [產品編號], ProductName AS [產品名稱], UnitPrice AS [單價] from Products;--select ProductID AS [品編號], ProductName AS [品名], UnitPrice AS [單價], UnitsInStock AS [庫存], UnitsOnOrder AS [在途數], ReorderLevel AS [再訂購量] from Productswhere UnitsInStock < ReorderLevel--select ProductID AS [品編號], ProductName AS [品名], UnitPrice AS [單價], UnitsInStock AS [庫存], UnitsOnOrder AS [在途數], ReorderLevel AS [再訂購量] from Productswhere (UnitsInStock+UnitsOnOrder) < ReorderLevel-- select ProductName AS [品名] from Productswhere ProductName like'%ku%'-- select CategoryID AS [類別],ProductName AS [品名] from Products-- where CategoryID = 1 or CategoryID =4 or CategoryID =8where CategoryID in (1,4,8)ORDER BY CategoryID,ProductName-- select UnitPrice AS [單價],ProductName AS [品名] from Products-- where UnitPrice >= 15 and UnitPrice<=20ORDER BY UnitPrice DESC--
--
select * from Products
--
select top 3 with ties ProductID AS [品編號],UnitPrice AS [單價],ProductName AS [品名] from Products
ORDER BY UnitPrice DESC
--
select avg(UnitPrice) AS [平均單價] from Products
--
select avg(UnitPrice) AS [指定類別平均單價] from Products
where CategoryID in (1,4,8)
--
select Products.CategoryID AS [類編號],CategoryName AS [類別],avg(UnitPrice) AS [各類平均單價] from Products
left join Categories on Products.CategoryID = Categories.CategoryID
GROUP BY Products.CategoryID,CategoryName
ORDER BY Products.CategoryID ASC
--
select top 3 with ties Products.CategoryID AS [類編號],CategoryName AS [類別],avg(UnitPrice) AS [平均單價] from Products
left join Categories on Products.CategoryID = Categories.CategoryID
GROUP BY Products.CategoryID,CategoryName
ORDER BY [平均單價] DESC
--
select top 1 with ties ProductID AS [品編號], ProductName AS [品名],UnitPrice AS [價格最高] from Products
ORDER BY [價格最高] DESC
--
select top 1 with ties ProductID AS [品編號], ProductName AS [品名],UnitPrice AS [價格最低] from Products
ORDER BY [價格最低] ASC
--
select ProductID AS [品編號], ProductName AS [品名], UnitPrice AS [價格最低]
from Products
where UnitPrice = (select min(UnitPrice) from Products);
-- select ProductID AS [品編號],
-- ProductName AS [品名],
-- Products.UnitPrice AS [價格最低]
-- from Products
-- join (
-- select min(UnitPrice) as MinPrice
-- from Products
-- ) m on Products.UnitPrice = m.MinPrice;