现在有4张表:   1.sending_email  总的发送列表,总共约1800W左右
              2.open_email     打开列表
              3.hb_email       硬弹回列表
              4.sb_email       软弹回列表四张表的结构相同,都有3列,为email,时间(emaildatetime)和项目名字(programmename),时间为每个email发送/打开/弹回的时间现在要做一张表,总数和发送表相同,为所有的发送过的email作统计,其格式为
email       发送时间    打开时间    硬弹回时间   软弹回时间   项目名称
1234@XXX    2008_1_1  2008_1_2                          abcd
1234@XXX    2008_2_1             2008_2_2               abcd
1234@XXX    2008_3_1                        2008_3_2    efgh注意:每一行里打开时间'硬弹回时'软弹回时间  只可能有1个值,即打开了就不可能被弹回,被硬弹回就不可能被软弹回
     一个email可能在不同项目里出现多次,也可能在一个项目里出现多次自己写了一小段:
select a.email,a.emaildatetime2 send_time,
(case when a.email in (select email from open_email where programmename=a.programmename) then b.emailtime else null end) open_time,
(case when a.email in (select email from hb_email where programmename=a.programmename) then c.emaildatetime2 else null end) hb_time,
(case when a.email in (select email from sb_email where programmename=a.programmename) then d.emaildatetime2 else null end) sb_time,
a.programmename
from sending_email a,open_email b,hb_email c,sb_email d
where 
请问后面的四表连接条件应该怎么写呢?高分跪求~~~~

解决方案 »

  1.   

    SELECT a.email         AS 邮箱
          ,a.emaildatetime AS 发送时间
          ,b.emaildatetime AS 打开时间
          ,c.emaildatetime AS 硬弹回时间
          ,d.emaildatetime AS 软弹回时间
          ,a.programmename AS 项目名称
      FROM sending_email a, open_email b, hb_email c, sb_email d
     WHERE a.email = b.email
           AND a.email = c.email
           AND a.email = c.email
           AND a.email = b.email
      

  2.   

    笔误
    SELECT a.email         AS 邮箱
          ,a.emaildatetime AS 发送时间
          ,b.emaildatetime AS 打开时间
          ,c.emaildatetime AS 硬弹回时间
          ,d.emaildatetime AS 软弹回时间
          ,a.programmename AS 项目名称
      FROM sending_email a, open_email b, hb_email c, sb_email d
     WHERE a.email = b.email
           AND a.email = c.email
           AND a.email = d.email
      

  3.   

    注意:每一行里打开时间'硬弹回时'软弹回时间  只可能有1个值,即打开了就不可能被弹回,被硬弹回就不可能被软弹回 
     =====================
    是你要这样显示?
    还是你几张表里就是这样设计,只能出现在一张表内?我看下来应该是几张表都有同一e_mail的纪录,所以你的语句不对,楼上的语句不对楼主贴一下表结构,再贴点数据上来,再贴你要的结果,直接帮你写sql
    你这样描述不清楚
      

  4.   

    要写外关联吧
    SELECT A.EMAIL         AS 邮箱,
           A.EMAILDATETIME AS 发送时间,
           B.EMAILDATETIME AS 打开时间,
           C.EMAILDATETIME AS 硬弹回时间,
           D.EMAILDATETIME AS 软弹回时间,
           A.PROGRAMMENAME AS 项目名称
      FROM SENDING_EMAIL A, OPEN_EMAIL B, HB_EMAIL C, SB_EMAIL D
     WHERE A.EMAIL = B.EMAIL(+)
       AND A.EMAIL = C.EMAIL(+)
       AND A.EMAIL = D.EMAIL(+)
      

  5.   

    sending的
                    email                   programmename     time
    1 [email protected] Century         2008-2-29 23:44:10
    2 [email protected] Century         2008-3-6  3:01:27
    3 [email protected] DOds         2008-2-27 16:34:18
    4 [email protected] CENT         2008-2-29 15:50:44
    5 [email protected]    Century         2008-2-29 15:50:44open 的
                    email                   programmename     time1 [email protected] Century         2008-3-1  22:18:22
    2 [email protected] DOds         2008-2-27 16:34:18hb  的1 [email protected] DOds         2008-2-29 8:12:50    
    2 [email protected]    CENT         2008-2-29 15:50:44sb  的1 [email protected] Century         2008-3-7 16:34:18想要的结果        email                   programmename        sendtime
    [email protected] Century         2008-2-29 23:44:10
    [email protected] Century         2008-3-6  3:01:27
    [email protected] DOds         2008-2-27 16:34:18
    [email protected] CENT         2008-2-29 15:50:44
    [email protected]    Century         2008-2-29 15:50:44     opentime                  hbtime                 sbtime        
    2008-3-1  22:18:22
                                                      2008-3-7 16:34:18
    2008-2-27 16:34:18
                             2008-2-29 15:50:44
                             2008-3-2  13:26:11
      

  6.   

    按你的数据就很简单了,按4楼的语句就行了
    看你的结构
    你sending表里纪录只会出现在open,hb,sb三张表的任意一张中,出现一次
      

  7.   

    我试着跑了这句语句,发现有逻辑错误:    email                   发送时间               打开时间              硬弹回时间      programmename
    [email protected] || 2008-2-27 16:34:18 ||2007-12-9 23:26:30 ||2007-12-3 11:43:05 ||21Century就是同一条发送记录即有打开时间又有硬弹回时间,要知道如果打开了的话是不可能被硬/软弹回的.