LeetCode数据库刷题笔记 - 简单

本文记录了在LeetCode上关于MySQL的刷题过程,包括对第二高薪水、重复电子邮箱、删除重复记录等问题的解答,探讨了SQL中的COUNT、DISTINCT、JOIN、GROUP BY等操作的使用细节和效率问题,以及对SQL语句性能优化的理解。
摘要由CSDN通过智能技术生成

176. 第二高的薪水

Q:为什么OFFSET 1,1 不可以?
A:如果所查询的表 或 where条件筛选后得到的结果集为空,那么聚合函数sum() 或 avg()的返回值为NULL;count()函数的返回值为0

 

182.查找重复电子邮箱

Q:What's the difference between COUNT(1), COUNT(*), COUNT(Email) ?

A:COUNT(*) will count the number of rows, while COUNT(expression) will count non-null values in expression and COUNT(column) will count all non-null values in the column.

Since both 0 and 1 are non-null values, COUNT(0)=COUNT(1) and they both will be equivalent to the number of rows COUNT(*). It's a different concept, but the result will be the same.

Q:MySQL中列名也不区分大小写吗?表名是否区分大小写?

A:On Windows, table names, database names and table aliases are not case sensitive. 

Field (column) names are case-insensitive regardless of the operating system. And you should not refer to a given database or table using different cases within the same statement. 

 

196. 删除重复邮箱

Q:

DELETE p1 FROM Person p1,
    Person p2
WHERE
    p1.Email = p2.Email AND p1.Id > p2.Id

delete will only delete the corresponding records? not the whole table?

A:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值