Skip to content
Advertisement

Counting entries in SQL which meet a selective criteria

I have a tables which stores the type of account users create for a product. There are 3 possible paths.

  1. They can either create a trial account, then create a full account.
  2. They can create a full account only.
  3. They can create trial account oly.

In the first case, 2 entries would be created, while the other cases would create 1 entry. example source table below:

I would like to calculate the number of users who created a trial account followed by a full account, as well as those who went straight to create a full one. envisioned final table below:

My query so far is :

but I realize it will not fulfill the criteria of counting users who only made a full account. Can somebody kindly help solve this?

Advertisement

Answer

You can use two levels of aggregation. I would put the counts in separate rows, like this:

You can easily modify this to put the values in columns instead:

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