首页 > 解决方案 > SQL Server 临时表从其他临时表插入

问题描述

临时表1

Col1 = Category1
Col1 = Category2

临时表2

30 records for a month

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

标签: sqlsql-servertsql

解决方案


你需要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;

推荐阅读