My FeedDiscussionsHeadless CMS
New
Sign in
Log inSign up
Learn more about Hashnode Headless CMSHashnode Headless CMS
Collaborate seamlessly with Hashnode Headless CMS for Enterprise.
Upgrade ✨Learn more

Counting length of period stored in SQL

Emil Moe's photo
Emil Moe
·Apr 13, 2017

I have a table in MariaDB that contains a population, this population is associated to a period and a person. On the population there's a boolean.

I need to calculate the lengths of those, which means if the population (that's a person and period combination) is true for 2 in a row, then the length is 2. If the last is true, then it's active, otherwise it's inactive.

I need to count all lengths, wether it's 1, 2 or more and need for every sum to know which period was the last one.

Does this makes sense?

It's okay if it's a heavy process, then I guess I just create a results table that's easy to read from, but I'm a little blank on the strategy to use here.