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

时间:2018-06-05 19:40:20

标签: sql sql-server tsql

TmpTable1

Col1 = Category1
Col1 = Category2

TmpTable2

30 records for a month

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

1 个答案:

答案 0 :(得分:1)

您需要cross join

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

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

select *
from table1 t1 cross join 
      table2 t2;