求个select 语句

森之树 2010-04-30 05:04:32
一张表,有3个字段,语文、数学、英语,分别有3条记录,语文70,数学80,英语58.请用一个查询语句查询出所有记录,并以下面格式显示出来,并写出你的思路。
80分为优秀,大于等于60为及格,小于60为不及格。

以下面的格式显示出来。
语文 数学 英语
及格 优秀 不及格
...全文
82 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
sxbjphg 2012-04-21
  • 打赏
  • 举报
回复
使用CASE 语句实现
kuxuan21 2010-07-13
  • 打赏
  • 举报
回复
select case 语文 when 语文-80>=0 then "优秀" when 语文-60>=0 then "及格" else "不及格" end as"语文" ,
case 数学 when 数学-80>=0 then "优秀" when 数学-60>=0 then "及格" else "不及格" end as"数学" ,
case 英语 when 英语-80>=0 then "优秀" when 英语-60>=0 then "及格" else "不及格" end as"英语"
from tb
森之树 2010-04-30
  • 打赏
  • 举报
回复
还有个问题 不会~

SendTime字段,在表A中,请搜索出表A中今天的所有SendTime记录。SendTime为DateTime类型。
abcdef1111111 2010-04-30
  • 打赏
  • 举报
回复

select case when 语文 >=80 then '优秀' when 语文 >=60 then '及格' else '不及格' as 语文,
select case when 数学 >=80 then '优秀' when 数学 >=60 then '及格' else '不及格' as 数学,
select case when 英语 >=80 then '优秀' when 英语 >=60 then '及格' else '不及格' as 英语from table
学习
hoojo 2010-04-30
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 dawugui 的回复:]
SQL code
select
case when 语文 >= 80 then '优秀' when 语文 >= 60 and 语文 < 80 then '及格' else '不及格' end 语文,
case when 数学 >= 80 then '优秀' when 数学 >= 60 and 数学 < 80 then '及格' else '不及格' end 数学,
case when 英……
[/Quote]
case when 用法参考
http://blog.csdn.net/IBM_hoojo/archive/2010/04/30/5546868.aspx
antony1029 2010-04-30
  • 打赏
  • 举报
回复
用 case 语句啊
--小F-- 2010-04-30
  • 打赏
  • 举报
回复
select
case when 语文>=80 then 优秀,
when 语文>=60 and 语文<80 then 及格,
when 语文<60 then 不及格
end as 语文,
case when 数学>=80 then 优秀,
when 数学>=60 and 数学<80 then 及格,
when 数学<60 then 不及格
end as 数学,
case when 英语>=80 then 优秀,
when 英语>=60 and 英语<80 then 及格,
when 英语<60 then 不及格
end as 英语
from
tb
永生天地 2010-04-30
  • 打赏
  • 举报
回复
'及格' :忘加'了
dawugui 2010-04-30
  • 打赏
  • 举报
回复
select 
case when 语文 >= 80 then '优秀' when 语文 >= 60 and 语文 < 80 then '及格' else '不及格' end 语文,
case when 数学 >= 80 then '优秀' when 数学 >= 60 and 数学 < 80 then '及格' else '不及格' end 数学,
case when 英语 >= 80 then '优秀' when 英语 >= 60 and 英语 < 80 then '及格' else '不及格' end 英语
from tb
永生天地 2010-04-30
  • 打赏
  • 举报
回复
(case when 语文<60 then'不及格' when 语文>=80 then '优秀' else 及格 end) as 语文,
(case when 数学<60 then'不及格' when 数学>=80 then '优秀' else 及格 end) as 数学,
(case when 英语<60 then'不及格' when 英语>=80 then '优秀' else 及格 end) as 英语
dawugui 2010-04-30
  • 打赏
  • 举报
回复
你就一条记录吧?哪里来的三条?

用case when end

34,588

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧