데이터 공부를 기록하는 공간

[SQL] 기본 Aggregate Function 본문

STUDY/SQL_HACKERRANK

[SQL] 기본 Aggregate Function

BOTTLE6 2021. 8. 17. 21:55

■ 코드카데미(codecademy) SQL 연습해보기

https://www.codecademy.com/courses/learn-sql/lessons/aggregate-functions/exercises/review

■ Cheating Sheets

https://www.codecademy.com/learn/learn-sql/modules/learn-sql-aggregate-functions/cheatsheet


LESSON 3 : Aggregate Function


COUNT()

SELECT COUNT(*)
FROM employees
WHERE experience <5;

SUM()

SELECT SUM(salary)
FROm salary_disbursement;

MAX() / MIN()

SELECT MAX(amount)
FROM transactions;
SELECT MIN(amount)
FROM transactions;

AVG()

SELECT AVG(salary)
FROM employees
WHERE experience < 5;

ROUND()

SELECT year,
    ROUND(AVG(rating),2)
FROM movies
WHERE year = 2015;

GROUP BY

SELECT rating,
    COUNT(*)
FROM movies
GROUP BY rating;
SELECT COUNT(*) AS 'total_movies',
    rating
FROM movies
GROUP BY 2
ORDER BY 1;

HAVING

SELECT year
    COUNT(*)
FROM movies
GROUP BY year
HAVING COUNT(*) > 5;

'STUDY > SQL_HACKERRANK' 카테고리의 다른 글

[hackerrank][SQL][Intermediate]  (0) 2021.10.18
[hackerrank][SQL][Basic]  (0) 2021.10.17
[SQL] Manipulation  (0) 2021.08.21
[SQL] Mutiple Tables  (0) 2021.08.17
[SQL] 기본 Queries  (0) 2021.08.16
Comments