简体   繁体   English

在SQL中合并两个没有公共列的表

[英]Merge two tables without common column in sql

I have two tables A and B. Table A contains field 'number'. 我有两个表A和B。表A包含字段“数字”。 Table B contains 'number_start' and 'number_end'. 表B包含“ number_start”和“ number_end”。 I want to merge these two tables such that final table contains details from both the table where number is between number_start and number_end. 我想合并这两个表,使最终表包含number在number_start和number_end之间的两个表的详细信息。

I want to achieve this in redshift /sql. 我想在redshift / sql中实现这一点。 let me know if anyone has some clue. 让我知道是否有人知道。

Perform this Join Operation 执行此加入操作

Select a.Number,b.EndNumber,b.StartNumber
from A a join B b
on  a.Number >= b.StartNumber and a.Number <= b.EndNumber

Use join statement. 使用join语句。 Try This. 尝试这个。

select t1.numbers from t1,t2 where t1.numbers>t2.min and t1.numbers<t2.max;
SELECT t1.`number`,t2.`end_number`, t2.`start_number` FROM table1 t1, `table2` t2
WHERE `number` >= start_number
AND number <=end_number

do you want some thing like this? 你想要这样的东西吗? Please check this 请检查一下

If both table is not related with each other then you can use this query 如果两个表都不相关,则可以使用此查询

select CONVERT(varchar, A.number_start) + CONVERT(varchar,B.number) + Convert(varchar,A.number_end)     from A cross join B

Or If this table has foreign key,then you can use inner join in this query 或者如果该表具有外键,则可以在此查询中使用内部联接

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM