SQL Basics - Functions & Group By 정보
SQL Basics - Functions & Group By본문
Order에서 총합을 구하는 함수
select sum(p.Price) Total
from customer.orders o
inner join Products p on o.ProductId=p.id
inner join Customer c on o.CustomerID=c.id;
이름별로 총합 구하기
select c.LastName, sum(p.Price) Total
from customer.orders o
inner join Products p on o.ProductId=p.id
inner join Customer c on o.CustomerID=c.id
group by c.LastName;
select c.LastName, p.ProductName, sum(p.Price) Total
from customer.orders o
inner join Products p on o.ProductId=p.id
inner join Customer c on o.CustomerID=c.id
group by c.LastName, p.ProductName;
시티별로 합과 평균을 구하기
select c.City, sum(p.Price) Total, avg(p.price)
from customer.orders o
inner join Products p on o.ProductId=p.id
inner join Customer c on o.CustomerID=c.id
group by c.City;
링크를 클릭하세요
공감
0
0
댓글 0개