SQL Basics - Functions & Group By > 그누5튜닝

그누5튜닝

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;

 

링크를 클릭하세요

https://youtu.be/9Pzj7Aj25lw?list=PLD20298E653A970F8&t=3413

공감
0
  • 복사

댓글 0개

© SIRSOFT
현재 페이지 제일 처음으로