Problem Description –
Since table Sales was filled manually in the year
product_name may contain leading and/or trailing white spaces, also they are case-insensitive.
Write an SQL query to report
product_namein lowercase without leading or trailing white spaces.
sale_datein the format
totalthe number of times the product was sold in this month.
Return the result table ordered by
product_name in ascending order. In case of a tie, order it by
sale_date in ascending order.
The query result format is in the following example.
Problem Link – Fix Product Name Format
Difficulty Level – Easy
SELECT LOWER(TRIM(product_name)) as product_name, DATE_FORMAT(sale_date, '%Y-%m') as sale_date, COUNT(sale_id) as total FROM sales GROUP BY 1, 2 ORDER BY 1, 2