英文:
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 <= 9)
BEGIN
PRINT 'The counter value is = ' + CONVERT(VARCHAR,@Counter)
SET @Counter = @Counter + 1
END
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论