-
SQL 학습(3) - Group by, Order by(작성중)Learning with online/SQL 2022. 11. 2. 23:49
SELECT name, count(*) from users
group by name
-- group by 이후, count(*) 집계함수를 작성
select name,count(*) from users
group by name;
select name, count(*) from users
where name = '신**'
group by name;
-- where 절과 group by 같이 쓰기
select name, email, count(*) from users
where email like '%naver.com' and
name = '이**'
group by name;
-- 주차별(week)로 코멘트(데이터) 갯수 구하기
select week, count(*) from checkins
group by week
-- 1주차 행수 : 96 비교해보기
select * from checkins
where week = 1;
select week, min(likes) from checkins
group by week;
select week, ROUND(avg(likes),2) from checkins
group by week
order by week desc;
-- Order by : 데이터를 정렬(asc, desc)
select week, count(*) from checkins
group by week
order by count(*) desc;
-- 웹개발 종합반의 결제수단별 주문건수 세어보기(+ 건수로 오름차순)
select course_title, payment_method, count(*) from orders
where course_title = '웹개발 종합반'
group by payment_method
order by count(*) asc;'Learning with online > SQL' 카테고리의 다른 글
SQL 학습(2) - Where절 조건문 (0) 2022.10.30 SQL 학습(1) - 설치 및 환경설정 (0) 2022.10.30 SQL 학습시작(feat.스파르타 코딩클럽) (0) 2022.10.30