将多个表与不同的日期值组合在一起

时间:2014-03-28 13:24:18

标签: sql sql-server

如标题所示,我想创建一个结合多个表和不同日期的视图。 表格如下:(示例)

OutlookEmailsPerDay:

enter image description here

OutlookAttachmentsPerDay:

enter image description here

OutlookSyncPerDay:

enter image description here

OutlookSentEmailsPerDay:

enter image description here

基于ComputerSystemId,我想加入这些表以获得类似于此问题中的结果: SQL - Combine two tables with different date value 相同的方法是否适用于两个以上的表。我知道我可以组合两个表然后添加另一个表等等,但是可以一步完成它吗?

1 个答案:

答案 0 :(得分:1)

试试这个,

select *
from OutlookEmailsPerDay emails
inner join OutlookAttachmentsPerDay attachments on emails.ComputerSystemId = attachments.ComputerSystemId
inner join OutlookSyncPerDay sync on emails.ComputerSystemId = sync.ComputerSystemId 
inner join OutlookSentEmailsPerDay sent on sent.ComputerSystemId  = emails.ComputerSystemId