dongtuo7364 2017-01-18 04:22
浏览 34
已采纳

如何将表中的一个值从另一个值分配给多个

I have 3 different tables:

process table:
| projectNo | process | studio |
+-----------+---------+--------+
| 170001    | ANM BLD | APEX   |
| 170001    | ANM BLD | CANVAS |
| 170002    | CGI MOD | APEX   |
| 170003    | CGI MOD | ORBIT  |

proc_leader table:
| projectNo | process | proc_leader|
+-----------+---------+------------+
| 170001    | ANM BLD | John       |
| 170001    | ANM BLD | James      |
| 170002    | CGI MOD | Peter      |
| 170003    | CGI MOD | Kate       |

proc_checker table:
| projectNo | process | proc_checker|
+-----------+---------+------------+
| 170001    | ANM BLD | Aaron      |
| 170001    | ANM BLD | John       |
| 170002    | CGI MOD | Peter      |
| 170003    | CGI MOD | Adel       |

So what i want to do is to create html table to look like this:

| username | studio APEX | studio CANVAS | studio ORBIT |
+----------+-------------+---------------+--------------+
| Aaron    |       x     |       x       |              |
| Adel     |             |               |       x      |
| John     |       x     |       x       |              |
| James    |       x     |       x       |              |
| Kate     |             |               |       x      |
| Peter    |       x     |               |              |

So I want to assign studio from process table to the username. Is it possible to do?

  • 写回答

3条回答 默认 最新

  • donglian1982 2017-01-18 04:31
    关注

    You can UNION the leader and checker table and LEFT JOIN it with the process table.

    Try this:

    select
      p2.proc_leader,
      case count(case when p1.studio = 'APEX' then 1 end) > 0 then 'x' end,
      case count(case when p1.studio = 'CANVAS' then 1 end) > 0 then 'x' end,
      case count(case when p1.studio = 'ORBIT' then 1 end) > 0 then 'x' end
    from process p1
    left join (
      select *
      from proc_leader
      union all
      select *
      from proc_checker
    ) p2 on p1.projectNo = p2.projectNo
    and p1.process = p2.process
    group by p2.proc_leader;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路