1. <strong id="7actg"></strong>
    2. <table id="7actg"></table>

    3. <address id="7actg"></address>
      <address id="7actg"></address>
      1. <object id="7actg"><tt id="7actg"></tt></object>

        ?LeetCode刷題實(shí)戰(zhàn)196:刪除重復(fù)的電子郵箱

        共 1329字,需瀏覽 3分鐘

         ·

        2021-02-27 14:01

        算法的重要性,我就不多說(shuō)了吧,想去大廠,就必須要經(jīng)過(guò)基礎(chǔ)知識(shí)和業(yè)務(wù)邏輯面試+算法面試。所以,為了提高大家的算法能力,這個(gè)公眾號(hào)后續(xù)每天帶大家做一道算法題,題目就從LeetCode上面選 !

        今天和大家聊的問(wèn)題叫做 刪除重復(fù)的電子郵箱,我們先來(lái)看題面:
        https://leetcode-cn.com/problems/delete-duplicate-emails/

        Write a SQL query to delete all duplicate email entries in a table named Person, keeping only unique emails based on its smallest Id.

        題意


        編寫(xiě)一個(gè) SQL 查詢,來(lái)刪除 Person 表中所有重復(fù)的電子郵箱,重復(fù)的郵箱里只保留 Id 最小 的那個(gè)。


        解題


        • 查詢目標(biāo):刪除一條記錄

        • 查詢范圍:Person表

        • 查詢條件:刪除所有重復(fù)的電子郵箱 ,重復(fù)的郵箱里只保留Id最小的哪個(gè)。
          顯然,通過(guò)這個(gè)查詢條件可以提取出來(lái)兩條
          and關(guān)系的條件:
          (1)找出所有重復(fù)的電子郵箱(2)刪除Id大的重復(fù)郵箱;
          對(duì)于條件(1),需要判斷出所有重復(fù)的電子郵箱,即
          p1.Email = p2.Email
          對(duì)于條件(2),需要判斷重復(fù)郵箱中Id較大的:
          p1.Id > p2.Id


        delete 
            p1
        from 
            Person p1,
            Person p2
        where 
            (p1.email = p2.email) and (p1.id > p2.id)


        好了,今天的文章就到這里,如果覺(jué)得有所收獲,請(qǐng)順手點(diǎn)個(gè)在看或者轉(zhuǎn)發(fā)吧,你們的支持是我最大的動(dòng)力 。

        上期推文:

        LeetCode1-180題匯總,希望對(duì)你有點(diǎn)幫助!
        LeetCode刷題實(shí)戰(zhàn)181:超過(guò)經(jīng)理收入的員工
        LeetCode刷題實(shí)戰(zhàn)182:查找重復(fù)的電子郵箱
        LeetCode刷題實(shí)戰(zhàn)183:從不訂購(gòu)的客戶
        LeetCode刷題實(shí)戰(zhàn)184:部門工資最高的員工
        LeetCode刷題實(shí)戰(zhàn)185:部門工資前三高的所有員工
        LeetCode刷題實(shí)戰(zhàn)186:翻轉(zhuǎn)字符串里的單詞 II
        LeetCode刷題實(shí)戰(zhàn)187:重復(fù)的DNA序列
        LeetCode刷題實(shí)戰(zhàn)188:買賣股票的最佳時(shí)機(jī) IV
        LeetCode刷題實(shí)戰(zhàn)189:旋轉(zhuǎn)數(shù)組
        LeetCode刷題實(shí)戰(zhàn)190:顛倒二進(jìn)制位
        LeetCode刷題實(shí)戰(zhàn)191:位1的個(gè)數(shù)
        LeetCode刷題實(shí)戰(zhàn)192:統(tǒng)計(jì)詞頻
        LeetCode刷題實(shí)戰(zhàn)193:有效電話號(hào)碼
        LeetCode刷題實(shí)戰(zhàn)194:轉(zhuǎn)置文件
        LeetCode刷題實(shí)戰(zhàn)195:第十行

        瀏覽 28
        點(diǎn)贊
        評(píng)論
        收藏
        分享

        手機(jī)掃一掃分享

        分享
        舉報(bào)
        評(píng)論
        圖片
        表情
        推薦
        點(diǎn)贊
        評(píng)論
        收藏
        分享

        手機(jī)掃一掃分享

        分享
        舉報(bào)
        1. <strong id="7actg"></strong>
        2. <table id="7actg"></table>

        3. <address id="7actg"></address>
          <address id="7actg"></address>
          1. <object id="7actg"><tt id="7actg"></tt></object>
            人人操人人搞 | 亚州无码免费 | 裸体黄色一级片 | 91福利视频网站 | a 在线视频 | 少妇高潮毛片免费看欧美一v | 成人小说黄色 | 亚洲精品成人影视 | 欧美日韩精品成人综合77777 | 国产宴妇精品久久久久久 |