是否可以从2个表中执行运行总计或累计和的子查询?结果将保存为“新值”。
第一张桌子:
var changes = R.Db(DbName).Table(TableName)
//.changes()[new {include_states = true, include_initial = true}]
.Changes()
.RunChanges<JObject>(conn);
changes.IsFeed.Should().BeTrue();
var observable = changes.ToObservable();
//use a new thread if you want to continue,
//otherwise, subscription will block.
observable.SubscribeOn(NewThreadScheduler.Default)
.Subscribe(
x => OnNext(x),
e => OnError(e),
() => OnCompleted()
);
第二张表:
CREATE TABLE data2 ( date1 DATE,mt int);
INSERT INTO data2 VALUES ('2018-01-01',76564);
INSERT INTO data2 VALUES ('2018-02-01',140005);
INSERT INTO data2 VALUES ('2018-03-01',231973);
INSERT INTO data2 VALUES ('2018-04-01',340085);
预期结果:
答案 0 :(得分:1)
假设new value
字段基于日期在两个表中总计运行,则下面的查询应该对您有用。
SELECT t.date, t.mt,
(@running_total := @running_total + t.mt) AS new_value
FROM (
SELECT date1 date, mt from data2
UNION ALL
SELECT date1 date, mt from bajet
) AS t
JOIN (SELECT @running_total := 0) r
ORDER BY t.date;