Skip to content

Tag: sql-server

How restart the incremenal from a temp table in SQL

I want to try to do an incremental number for a table, that has to return to 0 when seeing from the previous column (LAG) 0. This is what I tried to do: And this is what I am expecting to get out: I’m not familiar with the WITH common_table_expression is the right way to solve my problem? Answer You

How to get conditional SUM?

I am trying to get a conditional sum based on another column. For example, suppose I have this dataset: If there is a type of 1 then I only want that data for that data, else if there is only 0 then I want that data for that date. So for 12/16/2019 I would want the value 0. For 12/23/2019