gpt4 book ai didi

sql-server - 在 Microsoft SQL Server Management Studio 中创建 View 时遇到问题

转载 作者:行者123 更新时间:2023-12-03 01:34:36 25 4
gpt4 key购买 nike

我是 sql 的新手,正在努力制作 View 。这有效并将我需要的正确数据作为表格提取,但是当我将其作为 View 尝试时,出现错误:

SQL text cannot be represented in the grid pane and diagram pane.


SELECT [Data_Collector_ID],
[Batch_Info_ID],
[AssetTag],
[DateTimeStamp],
[Dust_Collector_DP]
FROM (
SELECT [Data_Collector_ID],
[Batch_Info_ID],
[AssetTag],
[DateTimeStamp],
[Dust_Collector_DP],
ROW_NUMBER() OVER (PARTITION BY [Batch_Info_ID] ORDER BY [DateTimeStamp] DESC) rn
FROM [PLCLogging].[dbo].[Coater_Data_Collector]
) tmp
WHERE rn = 1 AND ([DateTimeStamp] > DATEADD(DAY, -7, GETDATE()))
OR rn = 2 AND ([DateTimeStamp] > DATEADD(DAY, -7, GETDATE()))
ORDER BY DateTimeStamp DESC

知道如何让它作为 View 工作吗?

我试图为每个 Batch_Info_ID 提取两个最近的值在过去一周。如果我需要提供更多详细信息,请告诉我。

最佳答案

以下article讨论 View 设计器无法解释复杂的查询。

打开一个新的查询窗口并复制并粘贴以下文本并执行:

CREATE VIEW MyViewName
AS
SELECT [Data_Collector_ID],
[Batch_Info_ID],
[AssetTag],
[DateTimeStamp],
[Dust_Collector_DP]
FROM (
SELECT [Data_Collector_ID],
[Batch_Info_ID],
[AssetTag],
[DateTimeStamp],
[Dust_Collector_DP],
ROW_NUMBER() OVER (PARTITION BY [Batch_Info_ID] ORDER BY [DateTimeStamp] DESC) rn
FROM [PLCLogging].[dbo].[Coater_Data_Collector]
) tmp
WHERE rn = 1 AND ([DateTimeStamp] > DATEADD(DAY, -7, GETDATE()))
OR rn = 2 AND ([DateTimeStamp] > DATEADD(DAY, -7, GETDATE()))
ORDER BY DateTimeStamp DESC

关于sql-server - 在 Microsoft SQL Server Management Studio 中创建 View 时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34636981/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com