我有一个需要设置条件的 SQL 查询,这是我目前的 SQL 查询:
-- IF the video count is 1
UPDATE tbl_Video SET
[Featured] = 1
WHERE [VideoId] = 1
GO
-- ELSE IF Video Count is greater than 1
UPDATE tbl_Video SET
[Featured] = 0
WHERE [Featured] = 1
GO
-- Set the top 5 viewed videos as featured as default
UPDATE tbl_Video SET
[Featured] = 1
WHERE VideoId In (SELECT TOP 5 VideoId FROM tbl_Video
ORDER BY Views DESC)
GO
-- END
希望上面查询中的评论能够解释我想要实现的目标,场景是:
如果视频计数为 1,则在视频 Id = 1
的情况下将精选列设为真。如果视频计数大于 1,则将所有精选列标记为假,然后将观看次数最多的 5 个视频设为精选。
数据库是 SQL Server。
谢谢,