마

SQL Basics - Functions & Group By

· 2019-06-22 (토) 00:22:22 · 1021

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튜닝

64건
+
제목 글쓴이 날짜 조회
19-06-23 조회 1,187
19-06-23 조회 975
19-06-23 조회 1,054
19-06-23 조회 1,147
19-06-22 조회 1,421
19-06-22 조회 1,022
19-06-22 조회 854
19-06-22 조회 1,075
19-06-22 조회 894
19-06-21 조회 657
19-06-21 조회 802
19-06-21 조회 753
19-06-20 조회 736
19-06-20 조회 692
19-06-20 조회 1,320
19-06-19 조회 1,905
19-06-19 조회 1,623
19-06-18 조회 876
19-06-18 조회 868
19-06-17 조회 1,531
19-05-23 조회 776
18-07-14 조회 949
18-03-28 조회 1,232
15-11-22 조회 3,389
15-11-15 조회 2,626
15-10-29 조회 1,629
15-10-28 조회 1,768
15-10-28 조회 3,648
15-10-27 조회 1,246
15-10-27 조회 1,349