SQL Basics - Functions & Group By

· 6년 전 · 849

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

|
댓글을 작성하시려면 로그인이 필요합니다.

그누5튜닝

+
제목 글쓴이 날짜 조회
6년 전 조회 1,487
6년 전 조회 1,234
6년 전 조회 1,204
6년 전 조회 1,344
6년 전 조회 1,311
6년 전 조회 3,234
6년 전 조회 1,426
6년 전 조회 1,429
6년 전 조회 1,445
6년 전 조회 1,043
6년 전 조회 820
6년 전 조회 934
6년 전 조회 1,034
6년 전 조회 1,300
6년 전 조회 850
6년 전 조회 717
6년 전 조회 960
6년 전 조회 769
6년 전 조회 549
6년 전 조회 692
6년 전 조회 638
6년 전 조회 638
6년 전 조회 584
6년 전 조회 1,215
6년 전 조회 1,773
6년 전 조회 1,511
6년 전 조회 774
6년 전 조회 759
6년 전 조회 1,443
6년 전 조회 678