SQL Basics - Functions & Group By

· 6년 전 · 806

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,430
6년 전 조회 1,201
6년 전 조회 1,169
6년 전 조회 1,303
6년 전 조회 1,258
6년 전 조회 3,191
6년 전 조회 1,381
6년 전 조회 1,385
6년 전 조회 1,403
6년 전 조회 998
6년 전 조회 791
6년 전 조회 903
6년 전 조회 1,005
6년 전 조회 1,268
6년 전 조회 807
6년 전 조회 683
6년 전 조회 914
6년 전 조회 741
6년 전 조회 515
6년 전 조회 658
6년 전 조회 607
6년 전 조회 599
6년 전 조회 549
6년 전 조회 1,174
6년 전 조회 1,726
6년 전 조회 1,443
6년 전 조회 730
6년 전 조회 731
6년 전 조회 1,406
6년 전 조회 645
🐛 버그신고