Sql server计算列使用大于函数 [英] Sql server calculated column using greater than function
问题描述
您好我想在SQL Server 2008中使用大于函数,在我的表中我想显示以下列。
示例。
[关键] [作业] [测验] [考试] [成绩] [等级]
[1] [100] [100] [100] [100] [ A +]
[2] [90] [90] [90] [90] [A]
是否可以创建一个像这样的公式?使用计算任何想法如何解决这个问题?
成绩:结果=> 90A +
成绩:结果=> 80A
等级:结果=> 70B +
等级:结果=> 60b
我尝试了什么:
我已经尝试使用列创建表格,但我已经与等级叠加了。
Hello i want to use greater than function in SQL Server 2008, in my table i want to show this following column .
EXAMPLE.
[key][Homework][Quiz][Exam][Result][Grade]
[1] [100] [100] [100] [100] [A+]
[2] [90] [90] [90] [90] [A]
is it possible to create a formula like this?using computed any idea on how to fix this?
Grade:Result=>90"A+"
Grade:Result=>80"A"
Grade:Result=>70"B+"
Grade:Result=>60"b"
What I have tried:
I have tried already creating the table with the column but i'm stack with the Grade.
推荐答案
你可以使用case语句/表达来实现你想要的......
You can use "case" statement/expression to achieve what you want..
DECLARE @TestVal INT
SET @TestVal = 65
SELECT
CASE
WHEN @TestVal > 90 THEN 'A+'
WHEN @TestVal > 80 AND @TestVal <= 90 THEN 'A'
WHEN @TestVal > 70 AND @TestVal <= 80 THEN 'B+'
WHEN @TestVal > 60 THEN 'B'
END as Grade
在案例陈述之前使用你的其他列名并使用Grade列而不是上述查询中的@TestVal
use your other column names before the case statement and use Grade column instead of @TestVal in above query
这篇关于Sql server计算列使用大于函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!