SQL Training #13 - 21

· 6년 전 · 1106

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;

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;

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';

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;

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;

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

SQL Having

Where 와 Having의 차이점

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

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;

SQL As Statement

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

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

그누5튜닝

+
제목 글쓴이 날짜 조회
6년 전 조회 1,824
6년 전 조회 1,283
6년 전 조회 1,452
6년 전 조회 1,516
6년 전 조회 1,343
6년 전 조회 1,561
6년 전 조회 1,306
6년 전 조회 1,284
6년 전 조회 1,410
6년 전 조회 1,376
6년 전 조회 3,306
6년 전 조회 1,489
6년 전 조회 1,497
6년 전 조회 1,528
6년 전 조회 1,107
6년 전 조회 877
6년 전 조회 982
6년 전 조회 1,083
6년 전 조회 1,358
6년 전 조회 933
6년 전 조회 784
6년 전 조회 1,017
6년 전 조회 830
6년 전 조회 601
6년 전 조회 747
6년 전 조회 691
6년 전 조회 693
6년 전 조회 640
6년 전 조회 1,262
6년 전 조회 1,821