링크
https://leetcode.com/problems/product-sales-analysis-iii/description/
문제
Write a solution to select the product id, year, quantity, and price for the first year of every product sold.
Return the resulting table in any order.
The result format is in the following example.
정답
select product_id,
year as first_year,
quantity,
price
from sales
where (product_id, year) in (select product_id,
min(year)
from sales
group by product_id)
오답
select p.product_id,
min(year) as first_year,
quantity,
price
from product p
join sales s
on p.product_id = s.product_id
group by p.product_id
새롭게 이해한 내용
- 조건은 조건에 해당하는 게 정확하다
'[업무 지식] > MySQL' 카테고리의 다른 글
[LAG, LEAD] Exchange Seats (0) | 2024.11.08 |
---|---|
[UNION] Count Salary Categories (0) | 2024.11.07 |
[where & in ] Game Play Analysis IV (0) | 2024.10.30 |
[sum & case when] Queries Quality and Percentage (0) | 2024.10.29 |
[확인 비율 구하기] Confirmation Rate (0) | 2024.10.28 |