Skip to content
Advertisement

Tag: window-functions

MySQL Debit/Credit cumulative balance

I would like a cumulative DR or CR balance for the following table: For the above table, a cumulative Balance column would be: Decreasing a DR below 0 makes it a CR Decreasing a CR below 0 makes it a DR Where balance is 0, value is 0 DR It could be calculated as CR’s being a negative value, but

How to get the row index in SQLite3?

I have created a table that has a column of registration number as primary key. I have created row_id using row_number() that is ordered by the primary key. How can i search a registration number and get the row_id along with other information of that row? Answer If you have created the column row_id like: then use a CTE: Replace

How to pull a list of all visitor_ids that generated more than $500 combined in their first two sessions in the month of January 2020?

Tables: Sessions session_ts visitor_id vertical session_id Transactions session_ts session_id rev_bucket revenue Currently have the following query (using SQLite): I’m having trouble identifying the first two sessions that combine for $500. Open to any feedback and simplifying of query. Thanks! Answer You can use window functions and aggregation: The subquery joins the two tables, filters on the target month (note that

Advertisement