问个比较菜的sql语句
数据库表为
id first_name last_name major current_credits grade
1 10000 Scott Smith Computer Science 98
2 10001 Margaret Mason History 88
3 10002 Joanne Junebug Computer Science 75
4 10003 Manish Murgratroid Economics 66
对学生成绩分级别
update students
set grade = (
select grade from
(
select id,
case when current_credits > 90 then 'a'
when current_credits > 80 then 'b'
when current_credits > 70 then 'c'
else 'd' end grade
from students
) a
where a.id = students.id
);
请问大家为什么update student 的where语句写在括号里面就可以呢,说的稍微细一点。呵呵,刚刚研究sql比较菜。
补充下,上面的sql是可以简化的
UDPATE students
SET grade=(
CASE WHEN current_credits > 90 THEN 'a'
WHEN current_credits > 80 THEN 'b'
WHEN current_credits > 70 THEN 'c'
ELSE 'd'
相关问答:
小弟是个新手 现在有个问题一直不能解决
例如
procedure produce_proc
@p001 nvarchar(8000),
@p002 nvarchar(8000),
@p003 nvarchar(8000),
& ......
两种错误:
1.如果我这样申明:ResultSet rs;错误提示如下:
An error occurred at line: 51 in the jsp file: /index.jsp
The local variable rs may not have been initialized
48: ......
我有一个月和日组成的数字,有两组月和日
想在身份证号中挑选出在该该两组月日之间出生的人,不知道应该怎么写.
身份证号有可能是15位或者18位
月日组合的形式如下
10-17/04-20
月-日/月- ......
请问各位,如何将SQl中,某字段中的值横向展开呢,
CASE WHEN
具体问题具体分析,看你要怎么展开
姓名 科目 成绩
张三 英语 90
李四 英语&nb ......
我想使用Sql编个小程序,就是判定一个字符串出现了几次指定字符;
例如在string型“6+4+8+2”中,我需要判定出现了几个“+”;并且实现
if (出现3次)
then
………………(引发事件);
......