Skip to content

Tag: group-by

Summing condition excludes rows without positive sum

I’m having a weird issue where in returning the sum of rows where a condition is true seems to only return rows if that condition is true – or at least, it is excluding a large majority of the rows that would otherwise be returned. Original query – which returns all rows: For each row that w…

Optimize SQLite Query using GROUP BY

I am trying to optimize my query which uses GROUP BY. But can’t it takes too long time. I have a virtual table which contains 3 columns: I want the group to be just as the query below, but it just takes a bit too long to run. For example I tried this first which works pretty good but still

Identifying products that a customer owns

I want to check whether my customer owns an iPhone, iPad, or Macbook. I am not looking for how many iPhone or iPad or Macbook one customer has, I just want to identify if they own any of them, or if they own any two, or if they own all three. I am thinking of using the CASE WHEN function