'MySQL Query for finding customer interations

I have a MySQL table similar to below:

uniqueId | cUniqueId | steps | createdDate
      1  |       345 | step1 | 2015-11-29 02:10:27
      2  |       347 | step2 | 2015-11-29 02:10:27
      3  |       345 | step3 | 2015-11-29 02:10:27
      4  |       545 | step2 | 2015-11-29 02:10:27
      5  |       645 | step2 | 2015-11-29 02:10:27
      6  |       785 | step3 | 2015-11-29 02:10:27

I basically have 3 steps to filling out my application and every time a customer clicks on a step a row is added to my DB, the customers can go to any of the steps at any time and skip a step and then go back if needs be.

I'm attempting to get some insights into how customers interact but the main thing at the moment is working out how many customers went to each step first.

For instance if I had a sample of say 400 the data would look like:

FirstStep | amount
    Step1 | 200
    Step2 | 100
    Step3 | 100

This would mean that 100 users went to Step2 first etc

Any points in the right direction would be awesome!



Solution 1:[1]

This is working (it defines what step was first by date for each user). Replace table with your table name:

select `table`.`steps`,count(*)
from `table`
inner join (
  SELECT `cUniqueId`,min(`createdDate`) as `date` FROM `table` 
  group by `cUniqueId`
) as `t2` on 
  `table`.`cUniqueId` = `t2`.`cUniqueId` AND
  `table`.`createdDate` = `t2`.`date` 
group by `table`.`steps`

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Sam Ivichuk