Sql 子查询中的详细信息

Sql 子查询中的详细信息,sql,oracle,oracle11g,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 e

我必须从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
我的目标是从该选择中获取与原始表匹配的电子邮件 给我更多的细节

我一直在尝试这个查询:

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;
我期望这样的结果:

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

提前谢谢你

我看不到与
h.live\u overview\u 3的连接-那是什么?在任何情况下,您发布的查询(完整的查询)都应该失败,至少是因为
orderby
子句。您说的是按6排序,意思是按第六列排序,但您只选择了五列。还不清楚您将如何从该查询中获得“预期结果”,因为您只是从子查询中选择
mes
,而不是它计算的其他列。是的,thakn让我来解决这个问题,并希望它们连接在一起,尽管您在内部查询和外部查询中使用相同的别名
h
,我想这会导致错误。请在外部查询中为表
tbl1
指定不同的别名,例如
h2
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