
SQL 강의 듣기 (16강)
과제 및 요약 내용 정리하기
| 종류 | 설명 |
|---|---|
| count() | 개수 |
| sum() | 합계 |
| min() | 최소 |
| max() | 최대 |
| avg() | 평균 |
select count(*) from Customer;
select count(*) from Customer c inner join SalesOrder so
on (c.CustomerID = so.CustomerID)
where
c.CountryRegion='United States';
select
count(*) as Customers,
count(distinct CountryRegion) as Countries,
count(distinct City) as Cities
from Customer;
select
sum(SubTotal) as Order_Total,
max(UnitPrice) as Max_Price,
min(UnitPrice) as Min_Price,
avg(UnitPrice) as Avg_Price
from SalesOrderDetail
where SalesOrderID = 71780;
select avg(OrderQty)
from SalesOrderDetail sod inner join Product p
on (sod.ProductID = p.ProductID)
where p.ProductCategoryID = 6;
select avg(cast(OrderQty as numeric(5,0)))
from SalesOrderDetail sod inner join Product p on
(sod.ProductID = p.ProductID)
where p.ProductCategoryID = 6;
select
ProductID, size,
isnull(size, 'N/A') as Null_Size
from Product;
select
AddressLine1, AddressLine2,
AddressLine1 + ' ' + AddressLine2 as Full_Addr1,
isunll(AddressLine1,'') + ' ' +
isnull(AddressLine2,'') as Full_Addr2
from Customer;
select
count(p.ProductID) as Cnt,
avg(p.ListPrice) as Avg_ListPrice
from
Product p inner join ProductCategory pc
on (p.ProductCategoryID = pc.ProductCategoryID)
where pc.Name = 'Road Bikes';

select
count(*) as Tot_Orders
from
SalesOrder so inner join Customer c
on (so.CustomerID = c.CustomerID)
where c.title = 'Mr.'

select
count(distinct so.SalesOrderID) as Tot_Orders,
sum(sod.SubTotal) as Tot_Amount
from
SalesOrder so inner join SalesOrderDetail sod
on (so.SalesOrderID = sod.SalesOrderID)
inner join Customer c
on (so.CustomerID = c.CustomerID)
where c.CountryRegion = 'United Kingdom'
