고요빛물결

SQL Training #13 - 21

· 2019-06-23 (일) 02:07:00 · 1198

SQL Average Funcion

select avg(salary) as average_salary
from simpledb.employee;

select avg(salary) avg_manager_salary
from simpledb.employee
where job='Manager';

select avg(commission)
from simpledb.employee;

https://www.youtube.com/watch?v=9DLG0GBo0WE&list=PLD20298E653A970F8&index=13

SQL Count Function

select count(*)
from simpledb.employee;

select count(*)
from simpledb.employee
where job='Clerk';

select count(distinct job)
from simpledb.employee;

select count(commission)
from simpledb.employee;

https://www.youtube.com/watch?v=yY0Go4a4IZU&list=PLD20298E653A970F8&index=14

SQL Max Function

select max(salary)
from simpledb.employee;

select max(salary)
from simpledb.employee
where job='Clerk';

select max(salary)
from simpledb.employee
where job='Salesman' or job='Manager';

https://www.youtube.com/watch?v=TC4h5XN20-o&list=PLD20298E653A970F8&index=15

SQL Min Function

select min(salary)
from simpledb.employee;

select min(salary)
from simpledb.employee
where job='manager';

select min(salary)
from simpledb.employee
where job='manager' or job='Clerk';

select min(commission)
from simpledb.employee
where commission <> 0;

https://www.youtube.com/watch?v=VKJvhwrjU9U&list=PLD20298E653A970F8&index=16

SQL Sum Function

select sum(salary)
from simpledb.employee;

select sum(salary)
from simpledb.employee
where job='Manager';

select sum(salary) sum_salary, count(salary) count_salary, sum(salary)/count(salary), avg(salary)
from simpledb.employee;

https://www.youtube.com/watch?v=pI_n_RPcsnM&list=PLD20298E653A970F8&index=17

SQL Group By

select sum(salary)
from simpledb.employee;

select job, sum(salary)
from simpledb.employee
group by job;

select job, sum(salary), min(salary), max(salary), count(salary)
from simpledb.employee
group by job;

select salary, count(employee_name)
from simpledb.employee

https://www.youtube.com/watch?v=qpF7Y2fGTrE&list=PLD20298E653A970F8&index=18

SQL Having

Where 와 Having의 차이점

select job, sum(salary)
from simpledb.employee
group by job
having sum(salary) > 5000;

https://www.youtube.com/watch?v=9VnaNTBkdXQ&list=PLD20298E653A970F8&index=19

SQL Alias

select employee_name, job, salary+commission
from simpledb.employee;

select employee_name, job, salary+commission as total_salary
from simpledb.employee;

 

isnull이 아닌 ifnull이네요


select employee_name, job, salary+ifnull(commission, 0) as total_salary
from simpledb.employee;

select job, sum(salary) as salary_sum
from simpledb.employee
group by job;

https://www.youtube.com/watch?v=pk3EzzXpb9Q&list=PLD20298E653A970F8&index=20

SQL As Statement

select e1.*, sum(e1.salary)
from simpledb.employee as e1
group by e1.job;

https://www.youtube.com/watch?v=SJaZ5tcmfPk&list=PLD20298E653A970F8&index=21

|
댓글을 작성하시려면 로그인이 필요합니다.
+
제목 글쓴이 날짜 조회
19-06-23 조회 1,199
19-06-23 조회 984
19-06-23 조회 1,065
19-06-23 조회 1,155
19-06-22 조회 1,426
19-06-22 조회 1,028
19-06-22 조회 860
19-06-22 조회 1,080
19-06-22 조회 901
19-06-21 조회 663
19-06-21 조회 811
19-06-21 조회 759
19-06-20 조회 739
19-06-20 조회 699
19-06-20 조회 1,325
19-06-19 조회 1,914
19-06-19 조회 1,629
19-06-18 조회 887
19-06-18 조회 878
19-06-17 조회 1,541
19-05-23 조회 786
18-07-14 조회 955
18-03-28 조회 1,241
15-11-22 조회 3,396
15-11-15 조회 2,633
15-10-29 조회 1,639
15-10-28 조회 1,778
15-10-28 조회 3,656
15-10-27 조회 1,253
15-10-27 조회 1,355