zoukankan      html  css  js  c++  java
  • [LeetCode]196. 删除重复的电子邮箱(delete)

    题目

    编写一个 SQL 查询,来删除 Person 表中所有重复的电子邮箱,重复的邮箱里只保留 Id 最小 的那个。
    
    +----+------------------+
    | Id | Email            |
    +----+------------------+
    | 1  | john@example.com |
    | 2  | bob@example.com  |
    | 3  | john@example.com |
    +----+------------------+
    Id 是这个表的主键。
    例如,在运行你的查询语句之后,上面的 Person 表应返回以下几行:
    
    +----+------------------+
    | Id | Email            |
    +----+------------------+
    | 1  | john@example.com |
    | 2  | bob@example.com  |
    +----+------------------+
    
    来源:力扣(LeetCode)
    链接:https://leetcode-cn.com/problems/delete-duplicate-emails
    著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
    

    题解

    和select的笛卡尔积很像,具体删除表1的哪些会看where后面的东西。

    代码

    # Write your MySQL query statement below
    delete p1 from 
    Person p1,Person p2
    where p1.Email = p2.Email and p1.Id>p2.Id
    
  • 相关阅读:
    二叉树
    队列和栈
    时间复杂度和空间复杂度
    二分查找法
    排序算法值归并排序
    排序算法之选择排序类
    5.7.1.3 Global 对象的属性
    5.7.1.2 eval() 方法
    5.7.1.1 单体内置对象
    5.6.3.8 fromCharCode()方法
  • 原文地址:https://www.cnblogs.com/coding-gaga/p/12995785.html
Copyright © 2011-2022 走看看