我有一个表存储一周中的几天的数据。我想为一周中的每一天返回一行,即使我的表中一周中的那一天没有任何行。这是我当前的 sql 选择语句。
SELECT StoreID,
CASE
WHEN S.[DayOfWeek] = 1 THEN 'Sunday'
WHEN S.[DayOfWeek] = 2 THEN 'Monday'
WHEN S.[DayOfWeek] = 3 THEN 'Tuesday'
WHEN S.[DayOfWeek] = 4 THEN 'Wednesday'
WHEN S.[DayOfWeek] = 5 THEN 'Thursday'
WHEN S.[DayOfWeek] = 6 THEN 'Friday'
WHEN S.[DayOfWeek] = 7 THEN 'Saturday'
ELSE 'BAD'
END AS [DayOfWeek],
isOpen
FROM MyTable S
WHERE StoreID = @I_StoreID
ORDER BY S.[DayOfWeek]
现在它只返回星期一和星期二的记录,因为这就是他表中存在的所有内容,但我希望它也返回其他行,即使目前没有记录。谢谢!
编辑:
这是我所拥有的...
StoreID | DayOfWeek | isOpen
22 Sunday 0
22 Monday 1
29 Sunday 0
这是我希望得到的...
StoreID | DayOfWeek | isOpen
22 Sunday 0
22 Monday 1
22 Tuesday NULL
....
22 Saturday NULL
29 Sunday 1
29 Monday NULL
29 Tuesday NULL
....
29 Saturday NULL