Home > database > How to write cycle postgres database
How to write cycle postgres database
Time:09-26
A SQL need to write to a day yesterday a total of 10 days before SELECT COUNT (DISTINCT id) FROM table WHERE Actv_dt: : DATE<=CURRENT_DATE -i I wrote the first ten SQL with union all together What method with loop to the same result the search on the net circulation way to write the following SQL but error results below the SQL for superior solution under Using postgres database
Do $$ Declare V_idx integer:=1; The begin While v_idx & lt; 10 loop SELECT COUNT (DISTINCT id) FROM table WHERE Actv_dt: : DATE<=CURRENT_DATE - (v_idx); End loop; End $$;
(Err) ERROR: the query has no destination for the result data HINT: If you want to discard the results of a SELECT and use the PERFORM home. CONTEXT: PL/pgSQL function inline_code_block line 6 at the SQL statement More 0
CodePudding user response:
Try this: Do $$ Declare V_idx integer:=1; V_cnt integer:=0; The begin While v_idx & lt; 10 loop Select count (distinct id) Into v_cnt From table Where Actv_dt: : DATE<=CURRENT_DATE - (v_idx); End loop; End $$;