程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> SyBase數據庫 >> SyBase教程 >> DuplicateEmails

DuplicateEmails

編輯:SyBase教程

DuplicateEmails


    Write a SQL query to find all duplicate emails in a table named Person.

    +----+---------+
    | Id | Email   |
    +----+---------+
    | 1  | [email protected] |
    | 2  | [email protected] |
    | 3  | [email protected] |
    +----+---------+
    For example, your query should return the following for the above table:

    +---------+
    | Email   |
    +---------+
    | [email protected] |
    +---------+
Note: All emails are in lowercase.
    主要是group by的應用
    select Email from ( select Email,count(Email) as cnt from Person group by Email ) t where cnt>1;
    或者
    select Email from ( select Email,count(Email) as cnt from Person group by Email having cnt>1) t ;
    order by 要在group by 之後使用,不能在group by之前使用。
    select Email from ( select Email,count(Email) as cnt from Person order by Email group by Email ) t where cnt>1;
    這個執行會有問題。

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved