如何从两个 table 中减去两个列值并插入第三个 table
How to subtract two column values from two tables and insert in 3rd table
我正在使用 SQlite
Table A: 一列存储减去的值(差值)Table B: 一列带有unix时间戳(OFF_time)
Table C: 一列带有 unix 时间戳(ON_time)
必须分别从 table 的 B 和 C 中减去列 OFF_time 和 ON_time 的时间戳并存储在 A 中。
这是我尝试过的:
insert into A (difference) select B.OFF_time-C.ON_time from B,C;
[编辑]
没有错误,但是 Table A 是空的,没有更新差异。
样本数据:
TABLE C:
ON_time
TABLE乙:
OFF_time
期望输出:TABLE A:
差异(table A 中的列名)
622
1024
608
398
458
您可以使用 ROW_NUMBER() window 函数连接 B 和 C:
insert into A (difference)
select t1.OFF_time - t2.ON_time
from (select *, row_number() over (order by OFF_time) rn from B) t1
inner join (select *, row_number() over (order by ON_time) rn from C) t2
on t2.rn = t1.rn;
我正在使用 SQlite
Table A: 一列存储减去的值(差值)Table B: 一列带有unix时间戳(OFF_time) Table C: 一列带有 unix 时间戳(ON_time)
必须分别从 table 的 B 和 C 中减去列 OFF_time 和 ON_time 的时间戳并存储在 A 中。
这是我尝试过的:
insert into A (difference) select B.OFF_time-C.ON_time from B,C;
[编辑]
没有错误,但是 Table A 是空的,没有更新差异。
样本数据:
TABLE C: ON_time
TABLE乙: OFF_time
期望输出:TABLE A:
差异(table A 中的列名)
622
1024
608
398
458
您可以使用 ROW_NUMBER() window 函数连接 B 和 C:
insert into A (difference)
select t1.OFF_time - t2.ON_time
from (select *, row_number() over (order by OFF_time) rn from B) t1
inner join (select *, row_number() over (order by ON_time) rn from C) t2
on t2.rn = t1.rn;