Oracle Sql合并表有多个where子句

时间:2015-06-22 15:59:34

标签: mysql oracle

我的桌子:

Table 1
Pk     Type       EVENTID    TimeStamp                                Date
1      Audio1          1     11-JAN-15 12.33.49.000000000 AM           11-JAN-15
2      Video1          1     11-JAN-15 12.33.49.000000000 AM           11-JAN-15
3      Audio2          2     11-JAN-15 12.35.50.000000000 AM           11-JAN-15
4      Video2          2     11-JAN-15 12.35.50.000000000 AM           11-JAN-15
5      Audio3          3     11-JAN-15 12.33.49.000000000 AM           11-JAN-15
6      Video3          3     11-JAN-15 12.33.49.000000000 AM           11-JAN-15
7      Audio4          4     12-JAN-15 12.40.50.000000000 AM           12-JAN-15
8      Video4          4     12-JAN-15 12.40.50.000000000 AM           12-JAN-15


Table 2

Pk    EVENTID      TimeStamp                                
1        1        11-JAN-15 12.33.49.000000000 AM           
2        2        11-JAN-15 12.33.49.000000000 AM          
3        3        11-JAN-15 12.35.50.000000000 AM         
4        4        11-JAN-15 12.35.50.000000000 AM         

....
Table 3

Type        Type      EventId           TimeStamp                                Date
Audio1     Video1      1            11-JAN-15 12.33.49.000000000 AM           11-JAN-15
Audio2     Video2      2            11-JAN-15 12.33.50.000000000 AM           11-JAN-15
Audio3     Video3      3            11-JAN-15 12.35.50.000000000 AM           11-JAN-15
Audio4     Video4      4            11-JAN-15 12.40.50.000000000 AM           12-JAN-15

事件是唯一的价值。

我正在寻找下面的输出。

1 个答案:

答案 0 :(得分:-1)

Select a.typer, b.typer, a.EVENTID, a.TimeStampField, a.dateField from (
select * from table1 where typer like 'Audio%') a
left join
(select * from table1 where typer like 'Video%') b
on a.EVENTID = b.EVENTID
group by a.typer, b.typer, a.EVENTID, a.TimeStampField, a.dateField;

你走了。这是输出:

Type    Type    EVENTID TimeStampField  DateField
Audio1  Video1  1   11-JAN-15 12.33.49.000000000    11-JAN-15
Audio2  Video2  2   11-JAN-15 12.35.50.000000000    11-JAN-15
Audio3  Video3  3   11-JAN-15 12.33.49.000000000    11-JAN-15
Audio4  Video4  4   12-JAN-15 12.40.50.000000000    12-JAN-15

sql fiddle http://sqlfiddle.com/#!9/97718/2