我有一个名为 device_statistics 的表,它存储一个应用程序的设备信息,表创建脚本是:
CREATE TABLE public.device_statistics
(
id character varying(255) COLLATE pg_catalog."default" NOT NULL,
abnormalcount integer,
appid character varying(32) COLLATE pg_catalog."default" NOT NULL,
inactivecount integer,
offlinecount integer,
onlinecount integer,
statisticstime date,
totalcount integer,
CONSTRAINT ods_device_statistics_pkey PRIMARY KEY (id)
)
当设备离线时,我必须更新离线计数值,因为totalcount=abnormalcount + inactivecount + offlinecount + onlinecount这样我可以在异常计数、非活动计数、离线计数或在线计数更新时自动更新总计数值。
例如:
在设备离线之前,行如下(仅显示我们需要):
appid offlinecount totalcount
test 10 32
当设备离线并且我更新离线计数值时,我想要如下行:
appid offlinecount totalcount
test 9 31
totalcout 的值是自动更新的,怎么办?