如何在SQL查询中循环0-9?

huangapple go评论49阅读模式
英文:

How to loop through 0-9 in a sql query?

问题

Here's the translated code portion:

这是Redshift我有一个更新命令看起来像这样

UPDATE users
SET birthday = temp_users.birth_date
FROM public.users as gpu 
INNER JOIN temp_schema.users_birth_dates_with_row_numbers AS temp_users ON gpu.id = temp_users.id
WHERE mod(temp_users.row_id, 10) = 0 -- 这是我想要从0更改为9的部分
;

请让我知道如果您需要进一步的帮助。

英文:

This is redshift. I have an update command that looks like this:

UPDATE users
SET birthday = temp_users.birth_date
FROM public.users as gpu 
INNER JOIN temp_schema.users_birth_dates_with_row_numbers AS temp_users ON gpu.id = temp_users.id
WHERE mod(temp_users.row_id, 10) = 0 -- this is what I want to change from 0 -> 9
;

For context: I want to run this time times with a different modulo number. How can I do this? Row id is basically created with the row_number function and I want to do this in batches so that it doesn't hold any locks for too long.

答案1

得分: 2

SQL WHILE循环语法和示例
SQL中的WHILE循环语法如下:

WHILE condition
BEGIN
   {...statements...}
END

示例:

DECLARE @Counter INT 

SET @Counter=0
WHILE ( @Counter <= 9)
  BEGIN
  PRINT 'The counter value is = ' + CONVERT(VARCHAR,@Counter)
  SET @Counter  = @Counter  + 1
END
英文:

SQL WHILE loop syntax and example
The syntax of the WHILE loop in SQL looks like as follows:


WHILE condition
BEGIN
{...statements...}
END

Example:

DECLARE @Counter INT 

SET @Counter=0
WHILE ( @Counter &lt;= 9)
  BEGIN
  PRINT &#39;The counter value is = &#39; + CONVERT(VARCHAR,@Counter)
  SET @Counter  = @Counter  + 1
END

huangapple
  • 本文由 发表于 2023年1月6日 12:37:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/75026970.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定