Skip to content
Advertisement

(SQLite) Count number of times a value repeats 3 times continuously

I understand that this is a complex query, thus I have a separate column for this, but the column contains almost 99% values as null (which is very ineffecient), thus I want to know it its possible to do this through a query.

I have table something like this:

Now the query is, that if for 3 consecutive product ids, the corresponding value is 0 (in order of TransactionId ASC), then it will be counted as 1 for ProductId i.e.

How can we query this?

An optional short question :p

Is it alright if I have columns which have mostly null values?

Advertisement

Answer

In the more recent versions of SQLite, you can use lag()/lead():

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement