将行号添加到表中的字段

发布于 2025-02-13 07:56:15 字数 351 浏览 0 评论 0原文

我正在尝试获取此查询的输出,并在表中创建一个将显示的列:

SELECT cons_id, credited_date,
    ROW_NUMBER() OVER (partition by cons_id order by cons_id) AS Row_Counter
FROM fy23_jul_aug_anniv_jv;

我在表中创建了一个名为Counter的列,但似乎无法弄清楚如何使用其输出来更新它上述查询。请帮忙!谢谢!!

这是输出:

“在此处输入图像说明”

I'm trying to take the output of this query and create a column in my table that will display it:

SELECT cons_id, credited_date,
    ROW_NUMBER() OVER (partition by cons_id order by cons_id) AS Row_Counter
FROM fy23_jul_aug_anniv_jv;

I created a column in my table called COUNTER but cannot seem to be able to figure out how to update it with the output of the above query. Please help! Thanks!!

Here is the output:

enter image description here

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

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

发布评论

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

评论(1

苏别ゝ 2025-02-20 07:56:15

尝试使用以下查询:

UPDATE <your_tab_to_be_updated>
INNER JOIN (SELECT cons_id, 
                   credited_date,
                   ROW_NUMBER() OVER (partition by cons_id order by cons_id) AS Row_Counter
            FROM fy23_jul_aug_anniv_jv) cte 
        ON <your_tab_to_be_updated>.cons_id       = cte.cons_id
       AND <your_tab_to_be_updated>.credited_date = cte.credited_date
SET <your_tab_to_be_updated>.Row_Counter = cte.Row_Counter;

它将在您在查询中选择的其他两个列上使用原始表加入子查询,并将Row_number分配给原始表。

要进行更多故障排除,如果您可以从输入表中共享样本并相应的预期输出,我可以进一步提供帮助。

Try using the following query:

UPDATE <your_tab_to_be_updated>
INNER JOIN (SELECT cons_id, 
                   credited_date,
                   ROW_NUMBER() OVER (partition by cons_id order by cons_id) AS Row_Counter
            FROM fy23_jul_aug_anniv_jv) cte 
        ON <your_tab_to_be_updated>.cons_id       = cte.cons_id
       AND <your_tab_to_be_updated>.credited_date = cte.credited_date
SET <your_tab_to_be_updated>.Row_Counter = cte.Row_Counter;

It will join the subquery with your original table on the two other columns that you're selecting in your query, and assign the row_number to your original table.

For more troubleshooting, I can help further if you can share samples from your input tables and corresponding expected output.

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