您好以下查询不会返回所有项目和所有商店。它仅显示至少填写了一个状态日期的商店。
如何从项目表和商店中的所有商店获取所有项目,并显示商店的状态日期(无论何处填充)。
SELECT
ProjectName,Store,
MAX(CASE WHEN Activity = 'Visited' THEN Date ELSE NULL END) AS Visited,
MAX(CASE WHEN Activity = 'NotVisited' THEN Date ELSE NULL END) AS NotVisited,
MAX(CASE WHEN Activity = 'Finished' THEN Date ELSE NULL END) AS Finished
FROM Table1 T
INNER JOIN Project P
ON T.ProjectID = P.ProjectID
INNER JOIN Store S
ON T.StoreID = S.StoreID
INNER JOIN Activity A
ON T.ActivityID = A.ActivityID
GROUP BY ProjectName,Store