티스토리 뷰

Study/MySQL

SQL 고득점kit - GROUP BY

JJIINDOL 2025. 3. 5. 00:12

1. 월별 잡은 물고기 수 구하기

select count(*) as fish_count, month(time) as month
from fish_info
group by month(time)
order by month(time);

 

2. 물고기 종류 별 잡은 수 구하기

select count(a.fish_type) as fish_count, b.fish_name
from fish_info a inner join fish_name_info b
on a.fish_type = b.fish_type
group by fish_name
order by fish_count desc;

 

3. 자동차 종류 별 특정 옵션이 포함된 자동차 수 구하기

select car_type, count(*) as cars
from car_rental_company_car
WHERE options like '%통풍시트%'
   or options like'%열선시트%'
   or options like '%가죽시트%'
group by car_type
order by car_type asc;

'Study > MySQL' 카테고리의 다른 글

SQL 쿼리 순서  (0) 2023.09.10
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG
more
«   2025/09   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
글 보관함