简体   繁体   English

一个表数据作为另一表列中的列标题

[英]One Table Data as Column Headings in Another table Columns

Two Table 1.ClassSubjectTable and 2.SubjectTable 两张表1.ClassSubjectTable和2.SubjectTable

ClassSubjectTable 类主题表

------------------------------------
class_subject_id |subject1 |subject2
------------------------------------
  1 (General Id) |   1      |    2  -----> are subject_id's

SubjectTable 主题表

-------------------------
subject_id | subject_name
-------------------------
      1    |  Maths
      2    |  Science

I want to get 我想得到

------------------------------------
class_subject_id |subject1 |subject2
------------------------------------
       1         |Maths    | Science

More over there is no relation between them. 而且,它们之间没有关系。 Is it Possible? 可能吗? How? 怎么样?

Simple JOIN : 简单的JOIN

SELECT c.class_subject_id, s1.subject_name AS subject1, s2.subject_name AS subject2
FROM ClassSubjectTable c
LEFT JOIN SubjectTable s1
  ON c.subject1 = s1.subject_id
LEFT JOIN SubjectTable s2
  ON c.subject2 = s2.subject_id;

SqlFiddleDemo

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何根据同一表中的另一列数据填充一列? - How To Populate One Column Based On Another Columns Data In Same Table? 将数据从另一表的一列插入到同一表的多列中 - Inserting data into multiple columns of same table from one column of another table 如何从一个表数据复制列到另一表并在mysql中同时插入更多列? - how to copy column from one table data to another table and insert more columns same time in mysql? 在表格中使用一列1对colum2进行排序,并在列1中使用标题 - use one column 1 in table to sort colum2 and use column 1 as headings 如何将SQL表中的2列连接到另一个SQL表中的一列? - How to join 2 columns in a SQL table to one column in another SQL table? 将列数据从一个表复制到另一个表 - Copy columns data from one table to another 将一个表的两列连接到另一表的同一列 - Join two columns of one table to the same column of another table Sequelize将一张表的两列连接到另一张表的同一列 - Sequelize join two columns of one table to the same column of another table 将一个表的连接列与另一个表的一列组合成 JAVA object - combine joined columns of a table with one column of another table into JAVA object 获取具有一列的一个表的所有列,该列必须从与其数据对应的另一个表派生数据 - Get all Columns of One table having one column which has to derive data from another table corresponding to its data
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM