![](https://img-blog.csdnimg.cn/20190918140129601.png?x-oss-process=image/resize,m_fixed,h_224,w_224)
Database
文章平均质量分 53
Database related knowledge
胡小白的数据科学之路
https://www.zhihu.com/people/hu-jia-hao-10-2
展开
-
Leetcode 1501题: Countries You Can Safely Invest In
题目描述这道题,相对来说比较复杂,总共需要用到3张表,以及多次子查询。下面是3张表的信息。Person表±---------------±--------+| Column Name | Type |±---------------±--------+| id | int || name | varchar || phone_number | varchar |±-------原创 2021-09-17 20:36:03 · 342 阅读 · 0 评论 -
Leetcode 1484题: Group Sold Products By The Date
题目描述原始表有两个column,一个是产品的售卖日期,另一个是具体的产品名称。样例表题目要求:Write an SQL query to find for each date, the number of distinct products sold and their names.预期结果:My Answer其实这道题难度不大,唯一值得一提的就是如何在mysql进行字符串的拼接。我使用的是group_concat()函数,即对分组后的结果进行拼接。在函数中,我们可以自行定义拼接的符原创 2021-09-15 17:58:17 · 458 阅读 · 0 评论 -
Leetcode 1454题: Active Users (连续5天登录的用户)
题目描述这是一道非常经典的问题,连续n天登录的用户。之前在面试的时候也有被问到过,但是当时答的不好,这里在leetcode里再次碰到,所以做个总结,leetcode中问的是连续5天,但是我们希望将其拓展到连续n天。以下是题目中的原始表第一张是用户表,id列为主键。第二张表为登录信息,因为其中包含重复行,表示一个用户在同一天多次登录,所以这张表无主键。思路说实话,第一次遇到这个问题,我是懵逼的,唯一想到的方法就是创建多张子表,每张表的日期依次向前推一天,然后多表连接。但是这种方法显然低效。同时原创 2021-09-12 14:11:49 · 587 阅读 · 0 评论 -
Leetcode 1468题: Calculate Salaries
题目描述首先这是一张原始表,包含公司id,员工id,员工名字,以及工资。题目要求,将工资调整为税后工资。具体的税收标准为:The tax rate is calculated for each company based on the following criteria:0 If the max salary of any employee in the company is less than 1000 .0.24 If the max salary of any employee in t原创 2021-09-11 13:05:39 · 207 阅读 · 0 评论 -
mysql使用sum进行条件聚合
今天做到leetcode上的一道题, 题目的意思大概就是去筛选出同时购买了A商品和B商品却没有购买C商品的客户。Order表的字段信息如下:Table: Orders±--------------±--------+| Column Name | Type |±--------------±--------+| order_id | int || customer_id | int || product_name | varchar |±-----原创 2021-04-13 16:14:21 · 442 阅读 · 0 评论