AdoNetShop/database/04_queries.sql
2026-10-05 06:02:05 +05:00

29 lines
627 B
Transact-SQL
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- 04_queries.sql
-- Примеры запросов
USE [AdoNetShop];
GO
-- Получить все товары с названиями категорий
SELECT
p.Id,
p.Name,
p.Price,
p.StockQuantity,
c.Name AS CategoryName
FROM Products p
JOIN Categories c ON p.CategoryId = c.Id;
-- Получить все заказы клиента с деталями
SELECT
o.Id AS OrderId,
o.OrderDate,
o.TotalAmount,
p.Name AS ProductName,
oi.Quantity,
oi.Price
FROM Orders o
JOIN OrderItems oi ON o.Id = oi.OrderId
JOIN Products p ON oi.ProductId = p.Id
WHERE o.CustomerId = 1;