0

查询逻辑

我画了这张图片来解释我需要什么

1.比较两个不同表中的user_id和user_id

2.然后将两个表中的相应 ref_global_id 匹配到事件表

3.从事件表中匹配的global_id然后按升序排列。

4

3 回答 3

1

或这个:

    SELECT e.global_id, e.event_time
    FROM (SELECT * FROM table1
          UNION
          SELECT * FROM table2) x inner join
          event_table e ON e.global_id = x.ref_global_id
    WHERE x.[user_id] = 121
于 2012-10-05T07:25:22.910 回答
0
SELECT e.global_id, e.event_time
FROM events_table e
JOIN table1 t1 on e.global_id = t1.ref_global_id
JOIN table2 t2 on e.global_id = t2.ref_global_id
WHERE t1.user_id = 121 AND t2.user_id = 121
ORDER BY e.event_time
于 2012-10-05T07:23:51.357 回答
0

尝试这个:

select global_id, event_time from event left join table1 on event.global_id = table1.ref_global_id AND table1.user_id = 121 left join table2 on event.global_id = table2.ref_global_id AND table2.user_id = 121
于 2012-10-05T07:23:59.960 回答