下面的SQL查询产生重复的行。
不使用DISTINCT
子句,是否可以删除这些重复项?
SELECT RCY.Date,RCY.Period,RCY.Client,RCY.[Device Type],RCY.Metric,RCY.OS,RCY.Service,RCY.[User Type],RCY.Workload,RCY.Value,RCY.[Wow%],RCY.WoW - RPY.WoW AS YOY_WOW
FROM dbo.vw_Metric_WOW RCY LEFT OUTER JOIN vw_Metric_WOW RPY
ON RCY.period = RPY.period
AND RCY.metric = RPY.metric
AND RCY.workload = RPY.workload
AND RCY.client = RPY.client
AND RCY.service = RPY.service
AND RCY.os = RPY.os
AND RCY.[device type] = RPY.[device type]
AND RCY.[user type] = RPY.[user type]
AND RPY.date = DATEADD(YEAR, -1, RCY.date)
答案 0 :(得分:0)
首先,如果您试图获得2个表之间的“ WoW”差异,则必须使用“ INNER JOIN”或“ ISNULL(RPY.WoW,0)”
第二,只需尝试对该查询执行“ SELECT *”,然后在结果集中查找“更改”值。这可能会为您提供线索,以便将其他列添加到JOIN中。