【问题标题】:SQL Server Temp Table Insert from other temp table [closed]从其他临时表插入 SQL Server 临时表 [关闭]
【发布时间】:2018-06-05 19:40:20
【问题描述】:

TmpTable1

Col1 = Category1
Col1 = Category2

TmpTable2

30 records for a month

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

【问题讨论】:

  • 请阅读this,了解一些改进问题的技巧。

标签: sql sql-server tsql


【解决方案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;

【讨论】:

  • 不确定交叉联接如何每月返回 30 行。
  • @SeanLange。 . . 30 records for each Category so result will show 60 records
  • 我现在看到了你的解释。很难说他们真正想要什么是如此模糊。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-02-05
  • 2011-08-21
  • 1970-01-01
  • 1970-01-01
  • 2012-08-19
  • 1970-01-01
  • 2017-11-16
相关资源
最近更新 更多