1:对列进行逻辑判断
select ID,Score,
case
when Score>=90 then 'A'
when Score>=80 then 'B'
when Score>=70 then 'C'
when Score>=60 then 'D'
when Score>=50 then 'E'
end
from dbo.Scores

  

 
2:列转行
如果列名车位,某某,那么分数列
select stuNo,
sum(case when Subject='生物' then Score end) as 生物,
sum(case when Subject='数学' then Score end) as 数学,
sum(case when Subject='英语' then Score end) as 英语,
sum(case when Subject='语文' then Score end) as 语文
from dbo.Scores group by StuNo

  

sql-case列转行的更多相关文章

  1. Sql Server 列转行 Pivot使用

    今天正好做 数据展示,用到了列转行,行转列有多种方式,Pivot是其中的一种,Povit 是sql server 2005以后才出现的功能, 下面的业务场景: 每个月,进货渠道的总计数量[Total] ...

  2. Spark SQL中列转行(UNPIVOT)的两种方法

    行列之间的互相转换是ETL中的常见需求,在Spark SQL中,行转列有内建的PIVOT函数可用,没什么特别之处.而列转行要稍微麻烦点.本文整理了2种可行的列转行方法,供参考. 本文链接:https: ...

  3. (转)SQL Server 列转行

    原文:http://www.myexception.cn/sql-server/1078985.html1,2,3,4,5以上是一个字符串或则一逗号分隔的数字. 这里希望用一条语句查询出这样的效果: ...

  4. 关于sql 的列转行

    select * from TbaleOne unpivot(qty ])) as up go select * from TableTwo unpivot(grate for subject in ...

  5. sql server列转行的几种方法

    方法一,临时变量: declare @temp nvarchar(max)='' select @temp=coalesce(@temp,'')+Location+',' from( select d ...

  6. SQL行转列和列转行

    行列互转,是一个经常遇到的需求.实现的方法,有case when方式和2005之后的内置pivot和unpivot方法来实现. 在读了技术内幕那一节后,虽说这些解决方案早就用过了,却没有系统性的认识和 ...

  7. sql行转列和列转行(转)

    行列互转,是一个经常遇到的需求.实现的方法,有case when方式和2005之后的内置pivot和unpivot方法来实现. 在读了技术内幕那一节后,虽说这些解决方案早就用过了,却没有系统性的认识和 ...

  8. SQL列转行,行转列实现

    在工作中,大家可能会遇到一些SQL列转行.行转列的问题,恰好,我也遇到了,就在此记录一下.此处所用的是SQLServer2008R2. 行转列,列转行,都要预先知道要要处理多少数据,在此我就以三种方案 ...

  9. oracle 逗号分割,列转行,行转列

    SQL代码 列转行 select REGEXP_SUBSTR(a.rolecode ,,l) rolecode from ( select 'a,aa,aaa' rolecode from dual ...

  10. Hive(八)【行转列、列转行】

    目录 一.行转列 相关函数 concat concat_ws collect_set collect_list 需求 需求分析 数据准备 写SQL 二.列转行 相关函数 split explode l ...

随机推荐

  1. 用React.addons.TestUtils、Jasmine进行单元测试

    一.用到的工具 1.React.addons.TestUtils 2.Jasmine 3.Browserify(处理jsx文件的require依赖关系) 4.Reactify(能和browserify ...

  2. s1.charAt(x)=='a'

    public class hhh{public static void main(String[]args) {   String s1="hkdhskhegoihwhonfdsaaa&qu ...

  3. Quartz动态添加、修改和删除定时任务

    任务调度开源框架Quartz动态添加.修改和删除定时任务 Quartz 是个开源的作业调度框架,为在 Java 应用程序中进行作业调度提供了简单却强大的机制.Quartz框架包含了调度器监听.作业和触 ...

  4. 248. Strobogrammatic Number III

    题目: A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at ups ...

  5. C# 使用AutoResetEvent进行线程同步

    AutoResetEvent 允许线程通过发信号互相通信. 通常,当线程需要独占访问资源时使用该类. 线程通过调用 AutoResetEvent 上的 WaitOne 来等待信号. 如果 AutoRe ...

  6. android.content.Context 含义及使用

    Context字面意思上下文,位于framework package的android.content.Context中,其实该类为LONG型,类似Win32中的Handle句柄,很多方法需要通过Con ...

  7. C# WinForm窗体 控件Control 的 Invalidate、Update、Refresh的区别

    Control.Refresh - does an Control.Invalidate followed by Control.Update.Refresh: 强制控件使其工作区无效并立即重绘自己和 ...

  8. heatmap.2

    heatmap.2 {gplots} R Documentation Enhanced Heat Map Description A heat map is a false color image ( ...

  9. tc 2014 college tour 250 500

    题意: You are given a long long n. Return the largest divisor of n that is a perfect square. That is, ...

  10. Android 获取屏幕尺寸与密度

      android中获取屏幕的长于宽,参考了网上有很多代码,但结果与实际不符,如我的手机是i9000,屏幕大小是480*800px,得到的结果却为320*533 结果很不靠谱,于是自己写了几行代码,亲 ...