文章目录

  • 1. 题目
  • 2. 解题

1. 题目

Table: Sales

+--------------+---------+
| 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.

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

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.

The query result format is in the following example.

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.

来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/fix-product-name-format
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。

2. 解题

  • 大写upper\ucase,小写lower\lcase
  • 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_datefrom Sales
) t
group by product_name, sale_date
order by product_name, sale_date

我的CSDN博客地址 https://michael.blog.csdn.net/

长按或扫码关注我的公众号(Michael阿明),一起加油、一起学习进步!

LeetCode MySQL 1543. Fix Product Name Format(trim去空格+upper/lower大小写)相关推荐

  1. js实现trim()去空格

    https://blog.csdn.net/mafan121/article/details/51648003 trim()是一个很适用的方法,作用是去除字符串两边的空白,但是js本身并未提供这个方法 ...

  2. 字符串函数length求字符串长度upper,lower大小写转换ltrim,rtrim移除字符串左侧右侧的空白字符或其它预定义字符trim删除字符串前后的空格left,right,subtring

    length ltrim,rtrim left,right,subtring locate 定位 -instr instr(substr,str):返回str在substr字符串里第一次出现的位置,从 ...

  3. LeetCode MySQL解题目录

    已完成的 LeetCode MySQL 数据库题目.点击查看我的 LeetCode 算法解题目录. 已解决 123/123 - 简单 54 中等 51 困难 18 前置入门学习 MySQL 基本查询. ...

  4. LeetCode MySQL 1308. 不同性别每日分数总计(累加/变量/窗口函数)

    文章目录 1. 题目 2. 解题 1. 题目 表: Scores +---------------+---------+ | Column Name | Type | +--------------- ...

  5. 【回文串10】LeetCode 479. Largest Palindrome Product

    LeetCode 479. Largest Palindrome Product 本博客转载自:http://www.cnblogs.com/grandyang/p/7644725.html Solu ...

  6. java trim all,[JAVA中各种去除空格][java string.trim()][str.replaceAll去空格]

    有时候去除空格是件很烦的事,去空格我们也要详细了解一下他们的功能等,下面就罗列一下各个方法吧! 1. String.trim() trim()是去掉首尾空格 2.str.replace(" ...

  7. LeetCode MySQL 1549. The Most Recent Orders for Each Product

    文章目录 1. 题目 2. 解题 1. 题目 Table: Customers +---------------+---------+ | Column Name | Type | +-------- ...

  8. LeetCode MySQL 1511. Customer Order Frequency

    文章目录 1. 题目 2. 解题 1. 题目 Table: Customers +---------------+---------+ | Column Name | Type | +-------- ...

  9. LeetCode MySQL 1384. 按年度列出销售总额

    文章目录 1. 题目 2. 解题 1. 题目 Product 表: +---------------+---------+ | Column Name | Type | +-------------- ...

最新文章

  1. 专业研究HP procurve网络、阿姆瑞特和系统集成的论坛
  2. 贪心 ---- Codeforces Round #618 (Div. 2)B. Assigning to Classes+贪心[证明过程]
  3. 关于datagridview自动增加行高度和显示全部内容的设置
  4. linux 僵尸进程 defunct
  5. Mysql加锁过程详解(2)-关于mysql 幻读理解
  6. python序列_什么是Python的序列协议?
  7. [Qt教程] 第12篇 2D绘图(二)渐变填充
  8. P4550-收集邮票【期望dp】
  9. Dojo学习2 dojo快速安装
  10. java数据类型ppt,Java语言基础01数据类型02.ppt
  11. 揭秘微信红包:架构、抢红包算法、高并发和降级方案
  12. 李沐动手学深度学习V2-BERT预训练和代码实现
  13. PDF文件旋转最好用的方法
  14. 王者荣耀服务器维护多久结束,王者荣耀健康系统重置时间 时间限制规则详解...
  15. 种植业适宜性评价算法
  16. Relax中的量化管理
  17. 针对前端初级学者,如何在windows下搭建react-native环境详细教程
  18. 关于eMule下载伤硬盘的话题
  19. 没有权限访问储存此文件的计算机,win10你没有权限在此位置中保存文件的解决方法...
  20. 《七步走出职场焦虑©:释放压力,做情绪的主人》

热门文章

  1. excel合并两列内容_还在为合并WPS表格(Excel)中两列内容而犯愁?此方法简单高效...
  2. obs可以装手机吗?_原神PC和手机数据互通吗 PC和手机可以一起玩吗
  3. 数据结构探险——图篇
  4. uboot中关于LCD的代码分析
  5. ef sqlserver切换到mysql_可以为MySql和SqlServer使用EF上下文吗?
  6. memory拷贝与string拷贝的区别
  7. shell 需要注意的点
  8. 学习笔记=《你不知道的JavaScript(上卷)》第三章:函数作用域和块级作用域...
  9. 在unity 中,使用http请求,下载文件到可读可写路径
  10. mysql常见问题记录