我使用 SQL Anywhere 11。
我有以下看法:
CREATE MATERIALIZED VIEW "DBA"."PointsAcc"( /* view_column_name, ... */ )
IN "SYSTEM" AS
select sum(PL.Points) AS Sum, DP.UserUID, COUNT(*) AS cnt
FROM Points DP
KEY JOIN PointLine PL
KEY JOIN PointHead PH
GROUP BY DP.UserUID
我在 PointLine 中有一个触发器,应该从此视图中选择总和:
CREATE TRIGGER "WorkOnPoints" AFTER INSERT, DELETE
ORDER 1 ON "DBA"."Points"
REFERENCING OLD AS oldrow NEW AS newrow
FOR EACH ROW
BEGIN
declare @points integer;
set @points = (isnull((select isnull(Sum, 0)) FROM PointsAcc where UserUID = newrow.UserUID), 0))
END;
@points 变量现在包含插入或删除行之前的总和。如何从触发器中的视图中获取更新的总和?