简体   繁体   English

SQL 如何“加入”两个表

[英]SQL how to “join” two tables

can't imagine simple solution.无法想象简单的解决方案。 I've two tables.我有两张桌子。
table 1 (about 300 rows)表1(约300行)

id ID name姓名 time时间
ID1 ID1 peter彼得 12:00:00 12:00:00
ID2 ID2 alice爱丽丝 12:33:00 12:33:00
ID3 ID3 tom汤姆 08:00:00 08:00:00

table 2 (about 3'000'000 rows)表 2(约 3'000'000 行)

id ID time时间 arg1参数1
ID1 ID1 12:00:00 12:00:00 23 23
ID1 ID1 11:00:00 11:00:00 34 34
ID2 ID2 12:45:00 12:45:00 21 21
ID2 ID2 12:33:00 12:33:00 22 22
ID2 ID2 08:00:00 08:00:00 12 12
ID3 ID3 08:00:00 08:00:00 21 21
ID1 ID1 08:00:00 08:00:00 23 23

need output table like this需要像这样的 output 表

id ID name姓名 time时间 arg1参数1
ID1 ID1 peter彼得 12:00:00 12:00:00 23 23
ID2 ID2 alice爱丽丝 12:33:00 12:33:00 22 22
ID3 ID3 tom汤姆 08:00:00 08:00:00 21 21
Select t1.ID, t1.time, t1.name, t2.arg1 from table1 t1
Inner join table2 t2 on t2.id = t1.id
Where t1.time=t2.time

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM