[英]Snowflake While loop to continue sql until @Counter reaches 365
我試圖讓我的代碼在達到某個數字時停止計數,但是我不斷收到一個錯誤,即在聲明之后我無法使用 select 語句。
DECLARE @Counter INT
SET @Counter=1
WHILE ( @Counter <= 365)
BEGIN
select Geography
, concat('Latest_Week_End ',current_date - @Counter) as WE_DATE
,concat(Department_ID,' ',Department_NM)
,Group_NM
,concat(category_ID,' ',category_nm)
,Sum(Dollar_sales)
,Sum(dollar_Sales_ya)
,Sum(unit_sales)
,sum(unit_sales_ya)
,sum(rom_dollars)
,sum(rom_dollars_ya)
,sum(rom_units)
,sum(rom_units_ya) from TEMP_TABLES.MR_OMNIDASH_IRI_SHARE
where geography like '%PORTLAND%'
and WE_Date in (current_date - @Counter)
group by 1,2,3,4,5
SET @Counter = @Counter + 7
END
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.