我有这张桌子:
CREATE TABLE [Alerts]
(
[Timestamp] datetime,
[Status] int
)
INSERT INTO [Alerts] ([Timestamp], [Status])
VALUES
('2013-1-1 00:00:00', 1),
('2013-1-1 00:00:05', 1),
('2013-1-1 00:00:10', 2),
('2013-1-1 00:00:15', 2),
('2013-1-1 00:00:20', 0),
('2013-1-1 00:00:25', 1),
('2013-1-1 00:00:30', 1),
('2013-1-1 00:00:32', 2),
('2013-1-1 00:00:35', 2),
('2013-1-1 00:00:40', 0),
('2013-1-1 00:00:45', 0),
('2013-1-1 00:00:50', 0)
我如何从下面的代码中触发:
SELECT
MIN ([main].[Start]) AS [STOP_Begin],
[main].[End] AS [STOP_End],
DATEDIFF(s, MIN([main].[Start]), [main].[End]) AS [Interval_Second]
FROM
(
SELECT
[starts].[Start],
MIN([ends].[Timestamp]) AS [End]
FROM
(
SELECT
[Timestamp] AS [Start]
FROM [Alerts]
WHERE [Status] = 0
) AS [starts] LEFT JOIN [Alerts] AS [ends]
ON [starts].[Start] < [ends].[Timestamp]
AND [ends].[Status] <> 0
GROUP BY
[starts].[Start]
) AS [main]
GROUP BY
[main].[End]
ORDER BY 1
因此,每次我将新输入添加到表 [Alerts] 中时,
它都会自动更改新表。
我应该已经制作新桌子还是如何制作?
请看这个LINK
触发器代码,它和我的选择代码一样,只是说新表名newtable,
所以我每次添加新输入时都不需要使用我的选择代码