Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 在日期相同或过去的第一个id上加入_Sql_Google Bigquery - Fatal编程技术网

Sql 在日期相同或过去的第一个id上加入

Sql 在日期相同或过去的第一个id上加入,sql,google-bigquery,Sql,Google Bigquery,只有当表1的日期回答了问题的原始版本时,我才能将表1加入到opid的表2中 我想你想要一个完整的加入: select t1.id, t1.date, t1.spend, t2.id as table2_id, t2.users from table1 t1 full join table2 t2 on t1.date = t2.date; 我想你应该试试内部连接 选择t1.id、t1.date、t1.expense、t2.id作为表2\u id、t2.users 来自表1

只有当表1的日期回答了问题的原始版本时,我才能将表1加入到opid的表2中

我想你想要一个完整的加入:

select t1.id, t1.date, t1.spend, t2.id as table2_id, t2.users
from table1 t1 full join
     table2 t2
     on t1.date = t2.date;

我想你应该试试内部连接


选择t1.id、t1.date、t1.expense、t2.id作为表2\u id、t2.users
来自表1 t1内部联接
表2 t2

在t1.date,表2在表1的最新(日期)行与相同的
id2
连接,但不一定相同。
+------------+-------+-----+
| date       | users | opid|
+------------+-------+-----+
| 2019-07-06 | 100   |  1  |
+------------+-------+-----+
| 2019-07-08 | 200   |  2  | 
+------------+-------+-----+ 
+------------+-------+-------+
| date       | spend | users |
+------------+-------+-------+
| 2019-07-05 | 10    | 100   |
+------------+-------+-------+
| 2019-07-07 | 4     | null  |
+------------+-------+-------+
| 2019-07-08 | 6     | 200   |
+------------+-------+-------+  
select t1.id, t1.date, t1.spend, t2.id as table2_id, t2.users
from table1 t1 full join
     table2 t2
     on t1.date = t2.date;