返回信息流题目要求:
Write a SQL query to delete all duplicate email entries in a table named Person, keeping only unique emails based on its smallest Id.
+----+------------------+
| Id | Email |
+----+------------------+
| 1 | john@example.com |
| 2 | bob@example.com |
| 3 | john@example.com |
+----+------------------+
Id is the primary key column for this table.
For example, after running your query, the above Person table should have the following rows:
+----+------------------+
| Id | Email |
+----+------------------+
| 1 | john@example.com |
| 2 | bob@example.com |
+----+------------------+
网上的我看了,倒是挺好理解的,但我自己的代码WA却总是找不到错误,求各位大神指点
select * from Person
where Id in (select min(Id) from Person group by Email)
自己的电脑上是SQL Server,WA的例子跑完结果没有问题,应该是和MySQL语法上有什么差别吧,总之麻烦各位大神了
这是一条镜像帖。来源:北邮人论坛 / database / #10592同步于 2017/9/19
该镜像源已超过 30 天没有更新,可能在源站已被删除。
Database机器人发帖
LeetCode 196 Delete Duplicate Email 求问错误
Flying07
2017/9/19镜像同步5 回复
订阅后,新回复会通过你的通知中心匿名送达。
5 条回复
效果一样也不行么。。。关键是SQL Server和MySQL的运行结果不一样是什么原因
【 在 l11x0m7 (lxm) 的大作中提到: 】
: 这题需要你在原表上删除行
【 在 Flying07 的大作中提到: 】
: 效果一样也不行么。。。关键是SQL Server和MySQL的运行结果不一样是什么原因
??不是运行结果你不一样,是你自己调试的时候,返回的是select的结果,而leetcode上返回给你的是原表内容,如果你只做select,原表上内容是不变的。
返回原表。。。好吧。。。我懂了。。。感谢大神
【 在 l11x0m7 (lxm) 的大作中提到: 】
: ??不是运行结果你不一样,是你自己调试的时候,返回的是select的结果,而leetcode上返回给你的是原表内容,如果你只做select,原表上内容是不变的。