Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.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
在MySql中生成伪列_Mysql_Pivot Table - Fatal编程技术网

在MySql中生成伪列

在MySql中生成伪列,mysql,pivot-table,Mysql,Pivot Table,我有一个包含多个工作和多个部门的表,我希望以这样的方式处理数据,it将提供部门和工作方面的薪资信息。我怎样才能做到这一点?仅使用select和case或类似工具是否可以实现 输入表: +------+-----------+--------+--------+--------------+ | id | name | salary | deptno | job | +------+-----------+--------+--------+------------

我有一个包含多个工作和多个部门的表,我希望以这样的方式处理数据,it将提供部门和工作方面的薪资信息。我怎样才能做到这一点?仅使用select和case或类似工具是否可以实现

输入表:

+------+-----------+--------+--------+--------------+
| id   | name      | salary | deptno | job          |
+------+-----------+--------+--------+--------------+
|    1 | Lucas     |  20000 |      1 | Founder      |
|    2 | Gabriello |  18300 |      1 | Cofounder    |
|    3 | Teodoor   |  15000 |      2 | Sales        | 
|    4 | Ronna     |  12600 |      3 | Marketing    |
|    5 | Dixie     |   6800 |      3 | Janitor      |
|    6 | Kelsey    |   6400 |      2 | Janitor      |
|    7 | Tatiania  |  15200 |      2 | Sales        |
|    8 | Goldia    |  12400 |      3 | Marketing    |
+------+-----------+--------+--------+--------------+
deptno  Founder    Cofounder      Sales       Marketing   Janitor
------------------------------------------------------------------
  1      20000       18300          0             0         0
  2        0           0       15000+15200        0        6400
  3        0           0            0        12600+12400   6800
输出表:

+------+-----------+--------+--------+--------------+
| id   | name      | salary | deptno | job          |
+------+-----------+--------+--------+--------------+
|    1 | Lucas     |  20000 |      1 | Founder      |
|    2 | Gabriello |  18300 |      1 | Cofounder    |
|    3 | Teodoor   |  15000 |      2 | Sales        | 
|    4 | Ronna     |  12600 |      3 | Marketing    |
|    5 | Dixie     |   6800 |      3 | Janitor      |
|    6 | Kelsey    |   6400 |      2 | Janitor      |
|    7 | Tatiania  |  15200 |      2 | Sales        |
|    8 | Goldia    |  12400 |      3 | Marketing    |
+------+-----------+--------+--------+--------------+
deptno  Founder    Cofounder      Sales       Marketing   Janitor
------------------------------------------------------------------
  1      20000       18300          0             0         0
  2        0           0       15000+15200        0        6400
  3        0           0            0        12600+12400   6800

作为提醒,如果有人给了你有效的答案,请单击他们答案旁边的绿色复选标记,将其标记为“接受”答案。向上投票,因为Q和a是“数据透视表”中最简洁的。作为提醒,如果有人给了你有效的答案,请将其标记为“接受”点击答案旁边的绿色复选标记进行回答。向上投票,因为Q和A是“数据透视表”最简洁的选项之一。