SQL Server临时表从其他临时表插入

时间:2021-09-24 02:02:17

TmpTable1

Col1 = Category1
Col1 = Category2

TmpTable2

30 records for a month

How i can show 30 records for each Category so result will show 60 records

我如何能够为每个类别显示30条记录,因此结果将显示60条记录

1 个解决方案

#1


1  

You need cross join :

你需要交叉加入:

select t1.*, t2.category
from table1 t1 cross join 
       (select distinct category from table2) t2;

However if you don't have duplicate then you can directly express it as :

但是,如果您没有重复,那么您可以直接表达为:

select *
from table1 t1 cross join 
      table2 t2;

#1


1  

You need cross join :

你需要交叉加入:

select t1.*, t2.category
from table1 t1 cross join 
       (select distinct category from table2) t2;

However if you don't have duplicate then you can directly express it as :

但是,如果您没有重复,那么您可以直接表达为:

select *
from table1 t1 cross join 
      table2 t2;