在下表中,“Inverter_1.Eac1”列应根据该特定日期的最新时间戳显示值。每隔30分钟就有一个新数据进入并更新表格。如何创建一个视图,根据最新的时间戳为特定日期提供“Inverter_1.Eac1”的值?
SQL表
答案 0 :(得分:0)
如果您只想要Inverter_1.Eac1
列
CREATE VIEW view_name AS
SELECT `Inverter_1.Eac1` FROM
Table1
WHERE Tstamp IN (SELECT MAX(Tstamp) FROM Table1 GROUP BY SUBSTRING(Tstamp, 1, 10))
如果您想要使用所有列
CREATE VIEW view_name AS
SELECT T1.*
FROM Table1 T1
INNER JOIN
(SELECT Tstamp,`Inverter_1.Eac1` FROM Table1
WHERE Tstamp IN (SELECT MAX(Tstamp) FROM Table1 GROUP BY SUBSTRING(Tstamp, 1, 10))) AS T2
ON T1.Tstamp=T2.Tstamp AND T1.`Inverter_1.Eac1`=T2.`Inverter_1.Eac1`