【发布时间】:2016-01-18 17:18:40
【问题描述】:
我在一个 SQL 数据库中有 2 个表。
SELECT name from table1 ORDER BY name
SELECT name from table2 ORDER BY name
我想创建一个带有联合选择的存储过程,该过程创建一个具有以下输出的表 - 来自 table1 的五行和来自 table2 的一行,然后来自 table1 的 5 行和来自 table2 的一行等:
row 1 from table1
row 2 from table1
row 3 from table1
row 4 from table1
row 5 from table1
row 6 from table2
row 7 from table1
row 8 from table1
row 9 from table1
row 10 from table1
row 11 from table1
row 12 from table2
etc
这可能吗?如果是的话有什么提示吗? 谢谢
【问题讨论】:
-
为什么不在你的存储过程中有两个游标?
-
你能分享 t1 和 t2 的表模型和样本数据吗?您如何知道表格中哪一行是 #1 或 #5 以及它们的顺序是什么?
标签: sql sql-server stored-procedures