子查询的详细信息

时间:2017-01-17 22:46:17

标签: sql oracle oracle11g

我必须从tase表中的选择中获取详细信息,但似乎无法找到如何进行连接,这是我从此查询中获得的初始信息。

select /*+ Parallel 4*/
extract(month from h.ts1) mes, h.Email,
        count(case when h.id in ('3','4') then 1 end)  A,
        count(case when h.id not in ('3','4') and h.id is not null  then 1 end) F,
        count(case when h.id is null then 1 end)  N,
count(1) Total
from tbl1  h
where h.id2 = '21'
and h.ts2 >= timestamp '2016-12-01 00:00:00'
and h.ts2 < timestamp '2017-01-01 00:00:00'
and h.ts1 >= timestamp '2016-12-01 00:00:00'
and h.ts1 < timestamp '2017-01-01 00:00:00'
group by 
extract(month from h.ts1),
h.Email

获取此表:

MES  EMAIL              A   F   N   Total
__  ______________      __  __  __  __
12  NA@email.COM        16  9   315 340
12  AIR@email.COM       36  0   178 214
12  XGAD@email.COM      35  0   4   39
12  TEST@email.COM      0   0   35  35
12  E@email2.com        0   0   22  22
12  VI@email.COM        8   0   11  19
12  CL@email.NET        0   0   17  17
12  RH.GCM@email.COM    0   0   16  16
12  MA@email.COM        2   0   14  16

我的目标是让该选择的电子邮件与原始表格相匹配 并给我更多细节。

我一直在尝试这个问题:

select 
b.mes, h.email, h.ts3, h.detail1, h.detail_2
from tbl1 h     
inner join (
select /*+ Parallel 4*/
extract(month from h.ts1) mes, h.Email,
        count(case when h.id in ('3','4') then 1 end)  A,
        count(case when h.id not in ('3','4') and h.id is not null  then 1 end) F,
        count(case when h.id is null then 1 end)  N,
count(1) Total
from tbl1  h
where h.id2 = '21'
and h.ts2 >= timestamp '2016-12-01 00:00:00'
and h.ts2 < timestamp '2017-01-01 00:00:00'
and h.ts1 >= timestamp '2016-12-01 00:00:00'
and h.ts1 < timestamp '2017-01-01 00:00:00'
group by 
extract(month from h.ts1),
h.Email) b
on b.email=h.email
order by 1 desc;

但是它给我发了一个错误:

Error starting at line :  in command -
h.ts1
Error report -
Unknown Command

我希望结果如下:

MES  EMAIL              DETAIL1 DETAIL2     A   F   N   Total
__  ______________      ______  ________    __  __  __  __
12  NA@email.COM        rfeQR   WerdST      16  9   315 340
12  AIR@email.COM       ewfrT   qweQWq      36  0   178 214
12  XGAD@email.COM      qweeQ   qwedqw      35  0   4   39
12  TEST@email.COM      12DQD   DEfewE      0   0   35  35

提前谢谢!

0 个答案:

没有答案