I am getting the above error for the query below :
SELECT
a.stid, a.pfid, pf.pfname, a.mdid,
mm.mdDescription, a.categoryid, a.SummedSpace,
a.AvgSpace, mm.size_sqft as MML_size, a.TotalRev,
a.TotalProfit, a.wkCount, a.Lastwkinst
FROM
(SELECT wkid, stid, mdid, pfid, categoryid,
sum([space]) as SummedSpace, avg([space]) as AvgSpace,
sum(revenue) as TotalRev, sum(profit) as TotalProfit,
count(wkid) as wkCount, max(wkid) as Lastwkinst
FROM dbo.mdSpaceSales
WHERE wkid > 200936 AND categoryid in (25, 16, 62, 4079)
GROUP BY stid, mdid, pfid, categoryid) AS a
LEFT JOIN mdmasterlist mm ON mm.mdid = a.mdid
LEFT JOIN
(SELECT distinct pfid, [pf name] as pfname FROM mdmasterlist) AS pf
ON pf.pfid = a.pfid
ORDER BY
stid, categoryid, a.pfid, a.mdid
Could anyone help me with this error?