如何回答这个硬sql?

时间:2015-05-16 05:24:41

标签: sql

Chinook的IT经理有兴趣了解他们的客户是哪家电子邮件提供商 有关联。编写单个SQL语句以生成包含2列名为Email的列表 提供者和客户数量。电子邮件提供商应该在所有大写字母中显示(例如 GMAIL,YAHOO)和这些信息可以从客户的电子邮件地址获得。 来自同一提供商的电子邮件地址,包含不同的国家/地区代码(例如yahoo.com,yahoo.de, yahoo.ca)应被视为一个电子邮件提供商。首先按编号对查询结果进行排序 客户按降序排列,然后由电子邮件提供商按订单排序。

我尝试过:

    SELECT 
        Substr(email, Instr(Email), "@")+1,
        25-Instra(Substr(Substr(Email, "@")," "),".") AS "Email Provider", 
        COUNT(*) AS "No of Customers" 
    FROM 
        Customer 
    GROUP BY 
        UPPER(substr(Email,Instr(Email, "@")+2,Length(Substr(Substr(Email, "@"),".")"."));

1 个答案:

答案 0 :(得分:0)

select  substr( email
                , instr(email, '@')+1
                , instr(email, '.') - instr(email, '@')-1
                ) AS "Email Provider"
   COUNT(*) AS "No of Customers" 
    FROM 
        Customer 
    GROUP BY substr( email
                , instr(email, '@')+1
                , instr(email, '.') - instr(email, '@')-1
                ) 

希望有所帮助......