lundi 14 décembre 2015

Error in this subquery

I can't figure out why sql 2005 doesn't like it. It is giving me and error that says

Incorrect syntax near the keyword 'where'

on the RN=1 line.

left join (select tSpent, Customerid
from   (select SUM(spent) as tSpent, Customerid,
        RN = ROW_NUMBER() OVER (PARTITION BY Customerid ORDER BY Customerid DESC)
        from   Customer_Sales
        WHERE Customerid is not null)
              where   RN = 1) Sales ON Customer_Sales.Customerid = Data.Customerid

Aucun commentaire:

Enregistrer un commentaire