How can i get count of customers per day by unique and repeat customer for specific date?

前端 未结 3 1311
悲哀的现实
悲哀的现实 2021-01-07 14:32

I am trying to get a result from my order table to get list of counts of customers who 1st time ordered and repeat orders. Something like below.

Date               


        
3条回答
  •  孤街浪徒
    2021-01-07 15:05

    this is my answer but not sure is still can improve.

    SELECT userID, COUNT(*) AS repeat_order_cnt FROM
    (SELECT DATE(OrderDate) AS order_DT, userID, COUNT(*) AS no_of_order FROM order
    AND YEAR(orderDate) = '2015'
    AND MONTH(orderDate) = '01'
    GROUP BY order_DT,userID) AS order2
    GROUP BY userID
    HAVING COUNT(*) > 1
    

提交回复
热议问题