首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

请问一个sql有关问题,多谢了

2012-03-21 
请教一个sql问题,谢谢了有一张表有三个字段如语文,数学,英语,里面有三条数据,如下所示语文数学英语4570899

请教一个sql问题,谢谢了
有一张表有三个字段如语文,数学,英语,里面有三条数据,如下所示
  语文 数学 英语 
  45 70 89
  90 45 79
  89 89 89

要求显示为: 60 分以下的是差 60到80的为良 80以上的为好,如下所示

  语文 数学 英语
  差 良 好
  好 差 良
  好 好 好 


我想请教一下要实现这样的结果sql怎么写


[解决办法]

SQL code
if object_id('[tb]') is not null drop table [tb]gocreate table [tb]([语文] int,[数学] int,[英语] int)insert [tb]select 45,70,89 union allselect 90,45,79 union allselect 89,89,89goselect   语文=case when 语文<60 then '差' when 语文>=80  then '好' else '良' end,  数学=case when 数学<60 then '差' when 数学>=80  then '好' else '良' end,  英语=case when 英语<60 then '差' when 英语>=80  then '好' else '良' endfrom tb/**语文   数学   英语---- ---- ----差    良    好好    差    良好    好    好(3 行受影响)**/
[解决办法]
case when 判断一下就ok了。

热点排行