使用sql进行连接时的数据插入

时间:2016-05-17 07:24:34

标签: sql oracle

我有两个表t1和t2。我需要聚合值“COUNT”和每个表中第三个表中的时间。

t1

COUNT               TIME_AH
2                   17-MAY-16 12:00:00
3                   17-MAY-16 12:00:00
2                   17-MAY-16 12:00:00
12                  17-MAY-16 12:00:00
2                   17-MAY-16 12:00:00
12                  17-MAY-16 12:00:00

t2

COUNT       TIME_ZH
1           17-MAY-16 12:00:00
22          17-MAY-16 12:00:00
3           17-MAY-16 12:00:00
4           17-MAY-16 12:00:00

t3

OUTPUT_TABLE

COUNT_AH    COUNT_ZH    TIME_AH
19          30          17-MAY-16 12:00:00

我尝试过以下代码,但输出错误。

select sum(t1.count), sum(t2.count), sysdate
from t1,
     t2
where TIME_AH = (trunc(sysdate,'hh'));

请帮忙。

2 个答案:

答案 0 :(得分:0)

您可以使用sudo fuser -k 3000/tcp代替UNIONJOIN执行此操作:

CASE EXPRESSION

答案 1 :(得分:0)

试试这种方式

select sum(t.a),sum(t.b),t.sysdate from (
select sum(t1.count) as a, 0 as b, sysdate
from t1
where TIME_AH = (trunc(sysdate,'hh'))
union all
select 0 as a, sum(t2.count) as b, sysdate
from t2
where TIME_AH = (trunc(sysdate,'hh'))) as t group t.sysdate