SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Evangelist
    Join Date
    Aug 2010
    Posts
    503
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Calculating New vs Returning Customer Orders

    Hi all, I'm trying to pick my brains on how I can work out a percentage so I would know how many customers are new or returning. I can see customers who have more than one order but not sure how else I can do this, I'm sure it's pretty simple!

    Code MySQL:
    SELECT customers_id, customers_name, COUNT(*) AS occur FROM orders GROUP BY customers_id HAVING(occur)>1 ORDER BY occur DESC

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,014
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    how do you know a customer is a returning customer?

    versus a new customer who places two orders on her first visit?
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Evangelist
    Join Date
    Aug 2010
    Posts
    503
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi, a customer has to firstly create an account and I then store that account number in a column in the order table...

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,014
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by coxdabd View Post
    Hi, a customer has to firstly create an account and I then store that account number in a column in the order table...
    so...

    when you store that customer number into the first order created by that customer, it's a new customer, right?

    and when you store that customer number into the second order created by that customer, it's not a new customer, right?

    sounds like you answered your own question

    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •