如何加入2表和2个连接条件?

时间:2010-10-07 02:59:49

标签: sql-server

有谁知道如何加入2个表加2个连接条件?

〔实施例:

table 1
date        name     
2010-01-01  Ken      
2010-01-01  Alvin    
2010-01-03  Alvin    
2010-01-04  Ken      
2010-01-07  Amy 




table 2
date        name     count
2010-01-01  Ken      5
2010-01-01  Alvin    4
2010-01-04  Ken      1
2010-01-03  Alvin    0

如何在以下情况下将表1和表2连接在一起: table1 date = table2 date 和 table1 name = table2 name

1 个答案:

答案 0 :(得分:2)

SELECT 
    T1.*, T2.*
FROM 
    T1 JOIN T2 ON T1.date = T2.date AND t1.name = t2.name