본문 바로가기

SQL/StrataScratch

[MySQL] (Medium) New Products

문제: https://platform.stratascratch.com/coding/10318-new-products?code_type=3

 

 

나의 풀이:

select company_name
     , (net20 - net19) as total_launch
from (
    select company_name
         , count(case when year = 2020 then 1 else Null end) as net20
         , count(case when year = 2019 then 1 else Null end) as net19
    from car_launches
    group by company_name) tb;

꺄앙 오랜만에 한번에 맞춰서 기분이 좋당

 

그래도 문제를 이해하는데 시간이 좀 걸렸다.. 이해하고 보니 웃긴 건

'the number of products companies launched in 2020'

이거를 

'the number of products / companies launched in 2020' 이렇게 끊어서 이해하면 완전 쉬운데

'the number of products companies / launched in 2020' 처음에 이렇게 이해해서 먼 말이지,, 이랬다

정말 영어 실력이 썩어가고 있구나.. 😭 이번 주 부터 영어 공부를 다시 시작해서 다행이얌

 

솔루션:

select company_name, count(case when (year = 2020) then 1  end) - count(case when (year = 2019) then 1 end ) as total_launch from car_launches
group by company_name;

호홍 저랑 같군요

 

약간 다른점은 나는 else null 명시를 해주었고 솔루션은 안 해준거?

케이스에서 else 처리를 안 해주면 기본적으로 null이 들어간다고 했던 것 같기도 하고,,!

 

어제는 시간을 많이 썼는데 오늘은 금방 끝나서 넘 좋아!!!!!

'SQL > StrataScratch' 카테고리의 다른 글

[MySQL] (Medium) Acceptance Rate By Date  (0) 2024.02.09
[MySQL] (Medium) Risky Projects  (1) 2024.02.08
[MySQL] (Medium) Finding User Purchases  (2) 2024.02.07
[MySQL] Activity Rank  (0) 2024.02.01
[MySQL] (Medium) Users By Average Session Time  (2) 2024.01.31