This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-01-10
Channels
- # announcements (4)
- # babashka (40)
- # beginners (39)
- # calva (16)
- # cljdoc (1)
- # cljs-dev (8)
- # clojure (72)
- # clojure-europe (10)
- # clojure-losangeles (1)
- # clojure-nl (4)
- # clojure-spec (9)
- # clojure-uk (12)
- # clojurescript (16)
- # community-development (15)
- # conjure (5)
- # cursive (5)
- # datomic (26)
- # eastwood (1)
- # emacs (7)
- # events (1)
- # figwheel-main (15)
- # fulcro (27)
- # graphql (7)
- # gratitude (4)
- # introduce-yourself (1)
- # malli (4)
- # meander (4)
- # off-topic (2)
- # other-languages (13)
- # polylith (7)
- # reagent (5)
- # reitit (5)
- # shadow-cljs (27)
- # spacemacs (4)
- # sql (3)
- # tools-deps (6)
- # xtdb (13)
Anyone happen to know how to solve a SQL query where the value of one line depends on an aggregate calculated for the previous line? https://dba.stackexchange.com/questions/305881
@rovanion That requires a recursive cte. Here is an example in TSQL:
declare @transactions as table (
id integer primary key identity(1,1),
feed_g integer
);
insert into @transactions
values (50), (50), (50), (50);
with indexed_transactions as (
select *, row_number() over (order by id) as rn
from @transactions
),
cte as (
select cast(0 as bigint) as rn, 0 as id, 0 as feed_g, cast(0.0 as float) as row_weighted_sum
union all
select
a.rn,
a.id,
a.feed_g,
case when cte.row_weighted_sum + a.feed_g > 75 then cte.row_weighted_sum + a.feed_g
else cte.row_weighted_sum + a.feed_g * 0.5 end as row_weighted_sum
from indexed_transactions a
join cte on cte.rn = a.rn - 1
)
select * from cte where id > 0