mysql - SQL How can I get 0 as output (HAVING COUNT()) -


i having problem sql query. trying list of customer ids orders no (0) orders before 1 looked @ , orders 1 (1) order before 1 looked at. following query gives me expected results third line (count_compl_ord_before_d_1) no results second line (count_compl_ord_before_d_0):

select created_at d, customer_id b, (select customer_id orders customer_id = b , created_at < d , status = 'complete' having count(created_at) = 0 ) count_compl_ord_before_d_0, (select customer_id orders customer_id = b , created_at < d , status = 'complete' having count(created_at) = 1 ) count_compl_ord_before_d_1 orders status = 'complete' , created_at >= '2017-06-08' 

however, when run following, different amounts 0 xxx count_compl_ord_before_d:

select created_at d, customer_id b,   (select count(created_at) orders    customer_id = b , created_at < d      , status = 'complete') count_compl_ord_before_d orders status = 'complete' , created_at >= '2017-06-08' 

is problem having count(created_at) = 0?

i don't know lot sql, i'm trying learn more, i'd appreciate explanations.

thanks in advance! cheers


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -