Sql案例表达式声明 [英] Sql Case Expression Statement

查看:62
本文介绍了Sql案例表达式声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

id mark1 mark2 mark3

1 85 85 89

2 78 78 98

3 67 67 75

4 79 79 76

5 76 76 83



我有上表称为标记。我写了以下查询。



  SELECT  ID,< span class =code-keyword> CASE  MARK1 
WHEN mark1> 85 那么(MARK1 * 2)
ELSE MARK1
END
NEW MARK1
FROM 标记







如果标记1> 70我想将tat数据乘以2.但是当我运行tat查询时我得到以下错误。



'>'附近的语法不正确。 tat查询有什么问题?

解决方案

像这样使用..



  SELECT  ID, CASE   WHEN  mark1>  85  那么(MARK1 *  2 
ELSE MARK1 END [NEW MARK1]
FROM 标记


您在两个方面同时使用case语句



如果测试特定值,您可以:



  CASE  MARK1  WHEN   10  那么 doThis  ELSE  doThat  END  





或者您可以进行多种类型的测试:



  CASE   WHEN  MARK1>  10  那么 doThis  ELSE  doThat  END  





你写的是两者之间的混搭


id mark1 mark2 mark3
1 85 85 89
2 78 78 98
3 67 67 75
4 79 79 76
5 76 76 83

I have the above table called marks. I've written the following query.

SELECT ID, CASE MARK1
WHEN mark1 > 85 THEN (MARK1*2)
ELSE MARK1
END
"NEW MARK1"
FROM marks




If mark 1 > 70 i want to multiply tat data by 2. but when i run tat query i m getting the following error.

Incorrect syntax near '>'. what's wrong with tat query?

解决方案

Use it like this..

SELECT ID, CASE WHEN mark1 > 85 THEN (MARK1 * 2)
ELSE MARK1 END [NEW MARK1]
FROM marks


You're using the case statement in two ways at the same time

If testing for a specific value you can:

CASE MARK1 WHEN 10 THEN doThis ELSE doThat END



Or you can have multiple types of test like this:

CASE WHEN MARK1 > 10 THEN doThis ELSE doThat END



What you've written is a bit of a mash up between the two.


这篇关于Sql案例表达式声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆