首页 > 其他分享 >行列转换和活跃度计算

行列转换和活跃度计算

时间:2024-05-14 10:53:28浏览次数:16  
标签:转换 score 行列 student2 into course 活跃度 English Math

行列转换

建表

create table student2(
    id int,
    name varchar2(20),
    course varchar2(20),
    score int
);

数据:

insert into student2 values (1,'Tom','Chinese',80);
insert into student2 values (1,'Tom','Math',90);
insert into student2 values (1,'Tom','English',70);
insert into student2 values (2,'Bob','Chinese',90);
insert into student2 values (2,'Bob','Math',88);
insert into student2 values (2,'Bob','English',60);
insert into student2 values (3,'Jack','Chinese',96);
insert into student2 values (3,'Jack','Math',84);
insert into student2 values (3,'Jack','English',68);

行转列

select id,
       name,
       sum(case when course = 'Chinese' then score end) "Chinese",
       sum(case when course = 'Math' then score end)    "Math",
       sum(case when course = 'English' then score end) "English"
from student2
group by id, name;

 

将行转列代码生成新表

create table student3 as
select id,
       name,
       sum(case when course = 'Chinese' then score end) "Chinese",
       sum(case when course = 'Math' then score end)    "Math",
       sum(case when course = 'English' then score end) "English"
from student2
group by id, name;

列转行

select id, name, "Chinese" as score, 'Chinese' as course
from student3
union
select id, name, "Math" as score, 'Math' as course
from student3
union
select id, name, "English" as score, 'English' as course
from student3;

 

标签:转换,score,行列,student2,into,course,活跃度,English,Math
From: https://www.cnblogs.com/zuouncle/p/18190857

相关文章

  • 格雷码和二进制的转换
    格雷码和二进制的转换方法如下:二进制码转换成格雷码:方法是从二进制码的最右边一位(最低位)起,依次将每一位与左边一位进行异或运算,作为对应格雷码该位的值,而最左边高位不变。对应公式为:g[n]=b[n],g[i]=b[i]xorb[i+1](i∈N,n-1≥i≥1),其中g、b分别对应n位的格......
  • python 时间的访问和转换 time
    time说明Python的time模块提供了各种与时间处理相关的功能,包括获取当前时间、操作日期/时间以及执行与时间相关的各种其它功能。time常用函数time.time():返回当前时间的时间戳(自1970年1月1日以来的秒数)。time.sleep(seconds):让程序休眠指定的秒数。time.localtime():返回......
  • 马尔可夫转换MSVAR模型预测资产收益率时间序列可视化分析|附数据代码
    原文链接:https://tecdat.cn/?p=36166原文出处:拓端数据部落公众号在现代金融市场中,资产收益率序列的预测一直是投资者和金融机构关注的焦点。资产收益率的波动不仅反映了市场的风险水平,也直接影响到投资组合的表现和风险管理策略的制定。然而,金融市场的复杂性和不确定性使得资产......
  • 将bmp文件转换成JPEG(待修改,目前可转换但图片倒转)
    #include<stdio.h>#include<stdlib.h>#include<sys/types.h>#include<sys/stat.h>#include<fcntl.h>#include<unistd.h>#include<sys/mman.h>/**IncludefileforusersofJPEGlibrary.*Youwillneedtoha......
  • 用python将csv文件转换为exl文件
    使用pandas库:pandas相当于python中excel:它使用表(也就是dataframe),能在数据上做各种变换,但还有其他很多功能。os库:在使用之前都要先导入这个库(确保已经安装):下面是一个csv文件转成exl文件的实例:这个代码中定义了一个根据一定规则处理csv文件转exl文件的函数:首先导入了......
  • R语言中如何将科学计数法转换为数值型
     001、测试a<-c("1.23e-2","7.56207e-05","6.86470e-05")as.numeric(a)##直接转换为数值类型,然而并不起作用 02、增加参数options(scipen=100)##小数点后100位不适用科学计数法b<-c("1.23e-2","7.56207e-05","......
  • 音乐格式转换:java代码实现
    1packageutil;23importws.schild.jave.*;4importjava.io.File;56/*7音乐格式转换8<dependency>9<groupId>ws.schild</groupId>10<artifactId>jave-core</artifactId>11<version>2.4.4</versi......
  • C++类型转换
    一、整形提升整型提升是一种隐式类型转换,当涉及到小于int类型的整数(如char、short、bool等)时。整型提升的目的是确保所有的操作数在算术运算或比较操作中具有相同的类型,通常是int类型,如果int不能表示该值,则可能会提升到unsignedint或更大的整数类型。二、无符号数和带符号数进......
  • 使用TypeScript编写一个函数getPackageSize,该函数接收一个配置对象packageOpt作为参数
    使用TypeScript编写一个函数getPackageSize,该函数接收一个配置对象packageOpt作为参数,用于获取指定文件夹中所有文件的总大小,并根据配置决定是否返回已转换单位的大小值或直接通过回调函数返回字节大小。下面是一个基于Node.js环境的实现示例,因为直接在浏览器环境中操作文件系统......
  • 表格结构转换(Power Query)
    问题:左表转成右表let源=Excel.CurrentWorkbook(){[Name="表1_5"]}[Content],添加公司名列=Table.TransformColumns(Table.ExpandTableColumn(Table.Group(源,{"件号"},{"内容",eachTable.AddIndexColumn(_,"公司名",1)}),"内容"......