Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 如何在没有pivot函数的情况下透视表?_Sql - Fatal编程技术网

Sql 如何在没有pivot函数的情况下透视表?

Sql 如何在没有pivot函数的情况下透视表?,sql,Sql,我需要透视一个表,将行值转换为列,但关键是我没有可调用的透视功能。我需要找到一个解决办法来完成这件事 例如: NAME SUBJECT MARKS Adam maths 88 Adam Science 76 Matt Science 87 joe English 90 joe Maths 80 joe Science 40 Needs to look like :

我需要透视一个表,将行值转换为列,但关键是我没有可调用的透视功能。我需要找到一个解决办法来完成这件事

例如:

NAME   SUBJECT     MARKS
Adam    maths        88
Adam    Science      76
Matt    Science      87
joe     English      90 
joe     Maths        80 
joe     Science      40  

Needs to look like : 

NAME     SCIENCE   MATHS    ENGLISH   
Adam        76      88        null
Matt        87      null      null
Joe         40      80        90

我没有可用的枢轴功能

在没有pivot的情况下,聚合函数中的case语句可以得到相同的结果

select
    name,
    science = sum(case when subject = 'science' then marks else null end)
    maths = sum(case when subject = 'maths' then marks else null end)
from
    table
group by
    name

在没有pivot的情况下,聚合函数中的case语句可以得到相同的结果

select
    name,
    science = sum(case when subject = 'science' then marks else null end)
    maths = sum(case when subject = 'maths' then marks else null end)
from
    table
group by
    name

在没有pivot的情况下,聚合函数中的case语句可以得到相同的结果

select
    name,
    science = sum(case when subject = 'science' then marks else null end)
    maths = sum(case when subject = 'maths' then marks else null end)
from
    table
group by
    name

在没有pivot的情况下,聚合函数中的case语句可以得到相同的结果

select
    name,
    science = sum(case when subject = 'science' then marks else null end)
    maths = sum(case when subject = 'maths' then marks else null end)
from
    table
group by
    name


您使用的是哪种sql数据库?同样重要的是:到目前为止您尝试了什么?sql数据库是BigSQL,它是用于Hadoop发行版的IBM sql MPP引擎。到目前为止,我正在使用这里找到的左外连接,但这导致了一个结果,看起来像是
NAME科学数学英语Adam 76 null null Adam null 88 null Matt 87 null Joe 40 null Joenull 80 null Joe null 90
您使用的是哪种sql数据库?同样重要的是:到目前为止您尝试了什么?sql数据库是BigSQL,它是用于Hadoop发行版的IBM sql MPP引擎。到目前为止,我正在使用这里找到的左外连接,但这导致了一个结果,看起来像是
NAME科学数学英语Adam 76 null null Adam null 88 null Matt 87 null Joe 40 null Joenull 80 null Joe null 90
您使用的是哪种sql数据库?同样重要的是:到目前为止您尝试了什么?sql数据库是BigSQL,它是用于Hadoop发行版的IBM sql MPP引擎。到目前为止,我正在使用这里找到的左外连接,但这导致了一个结果,看起来像是
NAME科学数学英语Adam 76 null null Adam null 88 null Matt 87 null Joe 40 null Joenull 80 null Joe null 90
您使用的是哪种sql数据库?同样重要的是:到目前为止您尝试了什么?sql数据库是BigSQL,它是用于Hadoop发行版的IBM sql MPP引擎。到目前为止,我正在使用这里找到的左外连接,但这导致了一个结果,看起来像是
NAME科学数学英语Adam 76 null null Adam null 88 null Matt 87 null Joe 40 null Joenull 80 null Joe null 90
注意,如果可能的列没有固定,您将不得不走得更远一点。此外,我相信这将为不存在的分数打印0,而不是空值。如果列不固定,则必须使用动态sql,对于pivot也是如此。空值已更新,很好。请注意,如果可能的列不固定,您将不得不再进一步。此外,我相信这将为不存在的分数打印0,而不是空值。如果列不固定,则必须使用动态sql,对于pivot也是如此。空值已更新,很好。请注意,如果可能的列不固定,您将不得不再进一步。此外,我相信这将为不存在的分数打印0,而不是空值。如果列不固定,则必须使用动态sql,对于pivot也是如此。空值已更新,很好。请注意,如果可能的列不固定,您将不得不再进一步。此外,我相信这将为不存在的分数打印0,而不是空值。如果列不固定,则必须使用动态sql,对于pivot也是如此。空值已更新,捕捉良好。