0

对于以下查询,我收到“未返回任何结果”:

SELECT 
    Referer 
FROM 
    (SELECT 
        ROW_NUMBER() OVER (ORDER BY CT.Referer ASC) AS RowNum, 
        CT.Referer, CT.LastModified
     FROM 
        ClickTrack CT 
     JOIN 
        OrderTrack OT ON OT.ClickTrackID = CT.ClickTrackID              
     GROUP BY 
        CT.Referer, CT.LastModified
     HAVING 
        LEN(CT.Referer) > 0) as num 
WHERE 
    RowNum = 1 
    AND LastModified BETWEEN '07/06/2013' and '08/05/2013'

奇怪的是,当我离开时RowNum = 1,我得到了完整的值列表。我需要一次得到一个,但要分配给一个变量并放入一个临时表中。

结束查询将在 while 循环中使用标量变量代替日期范围和RowNum比较。

任何帮助表示赞赏。谢谢!

4

1 回答 1

1

我在想 RowNum 1 在您的选择之间可能没有日期。也许把日期选择放在里面,这样你就知道第一个匹配了。

    SELECT Referer 
    FROM (SELECT ROW_NUMBER() OVER (ORDER BY CT.Referer ASC) 
    AS RowNum, CT.Referer, CT.LastModified
    FROM ClickTrack CT 
    JOIN OrderTrack OT ON OT.ClickTrackID = CT.ClickTrackID    
    WHERE CT.LastModified BETWEEN '07/06/2013' and '08/05/2013'          
    GROUP BY CT.Referer, CT.LastModified
    HAVING LEN(CT.Referer) > 0) as num 
    WHERE RowNum = 1 
于 2013-08-07T21:59:04.533 回答