简体   繁体   English

如何在 SQL 中的 3 个不同表中加入一个低于另一个(不融合/合并数据)的 3 列?

[英]How can I join one below the other (not fusioning/merging data) 3 columns from 3 different tables in SQL?

On Pentaho - Spoon I want to select and join 3 columns which are fields related to Date and named differently, from 3 different tables (one field from each table), and join all the data in one single column that will be called Date.在 Pentaho - Spoon 上,我想要 select 并从 3 个不同的表(每个表中的一个字段)连接 3 个与日期相关的字段并以不同方式命名的列,并将所有数据连接到一个名为 Date 的列中。 I tried to do it with a step but couldn't find it so I think the easiest way is to write the script.我试着用一个步骤来做,但找不到它,所以我认为最简单的方法是编写脚本。 Any idea?任何想法? I am lost...Thanks!!我迷路了...谢谢!

I started with: SELECT dbo.SCHOOL.Date, dbo.STUDENT.Year, dbo.EXAMS.Year FROM dbo.SCHOOL, dbo.STUDENT, dbo.EXAMS我开始于:SELECT dbo.SCHOOL.Date, dbo.STUDENT.Year, dbo.EXAMS.Year FROM dbo.SCHOOL, dbo.STUDENT, dbo.EXAMS

use UNION not JOIN, if you want to merge data.如果要合并数据,请使用 UNION 而不是 JOIN。 If your all columns have the same data type (date).如果您的所有列都具有相同的数据类型(日期)。

SELECT Date, 'SchoolTable' FROM dbo.School
    UNION  
SELECT Year, 'StudentTable' FROM dbo.Student
    UNION
SELECT Year, 'ExamsTable' FROM dbo.Exams

or give more information about tables或提供有关表格的更多信息

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

相关问题 将2个不同表中的2列合并为一个列 - Merging 2 columns from 2 different tables into a single one SQL: 我如何加入不同的足球比赛桌? - SQL : How can i join different tables from competition of football? 连接来自不同表的不同列(SQL) - Join different columns from different tables (SQL) 如何连接来自不同表的数据? - How can I join data from different tables? 如何在没有在sql中进行连接的情况下从其他表中获取列 - how to have columns from other tables without doing a join in sql SQL:为什么我不能使用比较运算符通过连接比较来自两个不同表的两列? - SQL: Why can I not use comparison operators to compare two columns from two different tables using a join? 如何连接具有不同列的 3 个表? 获取数据类型错误 SQL 大查询 - How do I join 3 tables with different columns? Getting data type error SQL Big Query SQL oracle 如何将不同表中的两列相乘并将结果列放在两个表之一中 - SQL oracle How can i multiply two columns from different tables and put the resulting column in one of the two tables 如何使用SQL中其他列的数据? - How can I use data from other columns in SQL? 与其他表联接时,如何从同一表返回3个COUNT列? - How can I return 3 COUNT columns from the same table when JOIN with other tables as well?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM