我有一个视图表,其中包含以下内容
CAST(ROUND(SUM(dbo.TR.Score * 100) AS int) AS ScoreReached
我想将ScoreReached的数量限制为仅100(不能大于100)
我能这样做吗?答案 0 :(得分:1)
SELECT TOP 100 CAST(ROUND(SUM(dbo.TR.Score * 100) AS int) AS ScoreReached
FROM MyTable
如果我理解你的问题是对的。 这是TSQL的语法,您可以检查其他人here的语法。
答案 1 :(得分:1)
您可以使用 CASE ... WHEN 语法来约束ScoreReached列的值
SELECT CASE
WHEN TBL.ScoreReached > 100 THEN 100
ELSE TBL.ScoreReached
END AS ScoreReached
FROM (SELECT CAST(ROUND(SUM(dbo.TR.Score * 100), 0) AS INT) AS ScoreReached
FROM <your table name>) TBL