[英]sql create a view combining two tables
Table 1
id DATE column1 column2
. 。
Table 2
id DATE column1 column2
The output I want is: 我想要的输出是:
DATE {column1 from Table 1} {column2 from Table 2}
Obviously the DATE column is common for the two tables, the data from column1 & column2 differs I tried with create view and union from the two tables but the result is that it combines {column1 from Table 1} and {column2 from Table 2} into one column while what i want is these two to be created as two seperate columns 显然,DATE列对于两个表是通用的,column1和column2的数据与我尝试使用两个表的create view和union尝试的有所不同,但结果是它将{table 1的column1}和{table 2的column2}合并为一列,而我想要的是将这两列创建为两个单独的列
What you're looking for is a simple join
. 您正在寻找的是一个简单的
join
。
create view yourview as
select t1.date, t1.column1, t2.column2
from table1 t1
inner join table2 t2
on t1.date = t2.date
This assumes that you want column 1 from table1, column 2 from table2, where they share a common date. 假定您希望表1中的第1列,表2中的第2列共享相同的日期。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.