簡體   English   中英

不斷更新從另一個表創建的表

[英]Keep update a table created from another table

在 CrateDB 中,從另一個表的數據創建一個表后,是否可以通過從原始表中插入新行來保持新表的更新?

查詢以從enter code here創建new_table

CREATE TABLE "schema"."new_table" AS
SELECT
state,
time,
time - LAG(time, -1, time) OVER (ORDER BY time DESC) AS duration
FROM "schema"."original_table"
ORDER BY timeDESC;

查詢我定期運行以保持new_table更新,我想避免使用:

INSERT INTO "schema"."new_table"
SELECT
process,
time,
time- LAG(time, -1, time) OVER (ORDER BY time DESC) AS duration FROM "mtopcua_car"."original_table" newDataTable
WHERE NOT EXISTS (SELECT time FROM "schema"."new_table" WHERE time = newDataTable.time);

謝謝。

根據查詢的開銷,一個視圖可能就可以完成這項工作:

CREATE VIEW "schema"."new_view" AS
SELECT
    state,
    time,
    time - LAG(time, -1, time) OVER (ORDER BY time DESC) AS duration
FROM "schema"."original_table"
ORDER BY time DESC;

CrateDB 文檔: https://crate.io/docs/crate/reference/en/5.1/general/ddl/views.html

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM