Table: Sales Since table Sales was filled manually in the year 2000, product_name may contain leading and/or trailing white spaces, also they are case-insensitive. Write an SQL query to report The query result format is in the following example. 来源:力扣(LeetCode) 我的ImapBox博客地址 https://michael.blog.csdn.net/ 长按或扫码关注我的公众号(Michael阿明),一起加油、一起学习进步!1. 题目
+--------------+---------+ | Column Name | Type | +--------------+---------+ | sale_id | int | | product_name | varchar | | sale_date | date | +--------------+---------+ sale_id is the primary key for this table. Each row of this table contains the product name and the date it was sold.
product_name
in lowercase without leading or trailing white spaces.
sale_date
in the format ('YYYY-MM')
total
the 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.Sales +------------+------------------+--------------+ | sale_id | product_name | sale_date | +------------+------------------+--------------+ | 1 | LCPHONE | 2000-01-16 | | 2 | LCPhone | 2000-01-17 | | 3 | LcPhOnE | 2000-02-18 | | 4 | LCKeyCHAiN | 2000-02-19 | | 5 | LCKeyChain | 2000-02-28 | | 6 | Matryoshka | 2000-03-31 | +------------+------------------+--------------+ Result table: +--------------+--------------+----------+ | product_name | sale_date | total | +--------------+--------------+----------+ | lcphone | 2000-01 | 2 | | lckeychain | 2000-02 | 2 | | lcphone | 2000-02 | 1 | | matryoshka | 2000-03 | 1 | +--------------+--------------+----------+ In January, 2 LcPhones were sold, please note that the product names are not case sensitive and may contain spaces. In Februery, 2 LCKeychains and 1 LCPhone were sold. In March, 1 matryoshka was sold.
链接:https://leetcode-cn.com/problems/fix-product-name-format
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。2. 解题
upperucase
,小写lowerlcase
trim
去除空格,ltrim、rtrim
只去除左侧或者右侧空格# Write your MySQL query statement below select product_name, sale_date, count(*) total from ( select lcase(trim(product_name)) product_name, date_format(sale_date,'%Y-%m') sale_date from Sales ) t group by product_name, sale_date order by product_name, sale_date
本网页所有视频内容由 imoviebox边看边下-网页视频下载, iurlBox网页地址收藏管理器 下载并得到。
ImovieBox网页视频下载器 下载地址: ImovieBox网页视频下载器-最新版本下载
本文章由: imapbox邮箱云存储,邮箱网盘,ImageBox 图片批量下载器,网页图片批量下载专家,网页图片批量下载器,获取到文章图片,imoviebox网页视频批量下载器,下载视频内容,为您提供.
阅读和此文章类似的: 全球云计算