将结果集从哈希表分离到 3 个表中

发布于 2024-12-10 13:36:21 字数 437 浏览 0 评论 0原文

我使用的是 SQL Server 2008,并且有一个哈希表,其中包含有关邮政编码及其相关数据的数据。如果我按照 groupby 邮政编码计算记录数,

5000 HA
6000 NW
4000 S2

我想知道是否有任何方法可以将数据分成三个单独的表。 如果我们运行第一组记录,即 HA 看起来

Table1               Table2                   Table3
1st record of HA     2nd record of HA       3rd record of HA
4th record of HA     ....etc

是否可以使用光标或任何建议来实现?

任何帮助将不胜感激

谢谢

I am using SQL Server 2008 and have a hashtable which contains data about postcode and its related data. If I take the count of records groupby postcode its like this

5000 HA
6000 NW
4000 S2

I would like to know is there any way of devidng the data into three separate tables.
if we running the first set of records which is HA
which will look like

Table1               Table2                   Table3
1st record of HA     2nd record of HA       3rd record of HA
4th record of HA     ....etc

is it possible to achieve using cursor or any suggestion?

Any help will be appreciate

Thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

千年*琉璃梦 2024-12-17 13:36:21

我无法想象我会做这样的事情的任何可能原因。分成3张表会让数据以后查询起来更加困难。但如果您坚持下去,那么我会按照以下方式做一些事情:

建立一个包含三列 A、B、C 的映射表。用您想要在每个表中输入的值填充该表。应该看起来与此类似,但会输出您需要的最大值。

A   B   C
1   2   3
4   5   6
7   8   9
10  11  12

使用 row_number over 创建一个临时表(不要忘记排序依据),以便您现在可以知道哪条记录是第一个 HA,哪条记录是第二个等等。现在对您生成的每列 inteh 中的数字进行 3 次插入连接映射表。如果它们连接到A列插入到表A,列B插入到表B,列c插入到表c。

I can't imagine any possible reason why I would do such a thing. Dividing up into 3 tables will make the data much harder to query later. But if you're stuck with it then I would do something along the lines of this:

BUild a mapping table with three columns A, B, C. Populate the table withthe values you want to go in each table. Shoulf look simliar to this, but woudl go out the the max value you will need.

A   B   C
1   2   3
4   5   6
7   8   9
10  11  12

Create a temp table using row_number over (don't forget to order by) to so that you can now tell which record is the first HA and which is the second etc. Now do 3 inserts joining on the number you generated to each column inteh mapping table. If they join to column A insert to tableA, Column B, insert totable B, colmn c insert to table c.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文