Here is a way to do it in SQL, to generate a histogram and understand the percentage of your users which are logged in when checking out. select if(customer_id, 1, 0) as loggedin, count(*) from sales_flat_order where created_at > '2018-11-01' group by 1 order by 1 desc ; Outputs: +----------+----------+ | loggedin | count(*) | +----------+----------+ | 1 | 1194 | | 0 | 1693 | +----------+----------+