Results 1 to 9 of 9
  1. #1
    Join Date
    May 2005
    Posts
    110
    Plugin Contributions
    0

    Default Report on return customers

    Hi,

    I would like to know if there is anything out there which could report on return customers. Ie. 20% of customers have purchased once, 35% of customers have purchased twice, 50% of customers have purchased 2 - 3 times.

    If anyone has an idea on an sql query on the orders table which would give me some results that would even do.

    Thanks,
    Brad.

  2. #2
    Join Date
    Jan 2004
    Posts
    66,446
    Plugin Contributions
    81

    Default Re: Report on return customers

    This may look odd, but it should work as-is, on MySQL 5.0 or greater:
    Code:
    SET @custcount=0;
    SELECT (@custcount:=count(*)) as custcount 
    FROM customers;
    SELECT numorders, count(numorders) as numcusts, @custcount as totalcustomers, count(numorders)/@custcount as percent
    FROM (SELECT count(orders_id) AS numorders 
    FROM  orders GROUP BY customers_id) o
    GROUP BY (o.numorders) ORDER BY numorders DESC;
    If you're using custom table prefixes, you'll need to add your prefix to the two highlighted tablenames.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  3. #3
    Join Date
    May 2005
    Posts
    110
    Plugin Contributions
    0

    Default Re: Report on return customers

    Hi,

    Thanks for that, i just tested it and it works fine but im not sure how accurate it is because when i add up the columns they don't match, ie. the percentages total is 76.8% when it should be 100%.

    Brad.

  4. #4
    Join Date
    Jan 2004
    Posts
    66,446
    Plugin Contributions
    81

    Default Re: Report on return customers

    It doesn't tell you how many customers have never ordered ... I guess that's the remaining amount?
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  5. #5
    Join Date
    Sep 2004
    Location
    Murfreesboro, TN
    Posts
    588
    Plugin Contributions
    0

    Default Re: Report on return customers

    I came across this post by accident looking for something else, but I found what the original question to be very interesting. I have tried this query to see what result I would get and received the following error.

    1064 - You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT count(orders_id) AS numorders
    FROM zen_orders GROUP B

    I made sure that I changed the lines to accommodate for the table prefixes. Our hosted server is also running MySQL version 4.0.26. I even tried to run the the SQL executor directly in Zen Cart and still had errors.

    Any ideas on what to change?

    tia...

    0be1
    "Give me one hundred preachers who fear nothing but sin and desire nothing but God, and I care not whether they be clergymen or laymen, they alone will shake the gates of Hell and set up the kingdom of Heaven upon Earth." - John Wesley

  6. #6
    Join Date
    Jan 2004
    Posts
    66,446
    Plugin Contributions
    81

    Default Re: Report on return customers

    The query I posted uses a derived table, which is akin to subselects. Some of these features are not available on older versions of MySQL.
    I wrote and tested it on MySQL 5.0.
    I'm not sure if it works in 4.1. From your post it obviously doesn't work in 4.0.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  7. #7
    Join Date
    Sep 2004
    Location
    Murfreesboro, TN
    Posts
    588
    Plugin Contributions
    0

    Default Re: Report on return customers

    Thanks Dr. Byte... but can the query be re-written to work in 4.0 or are us dark ages people out of luck

    0be1
    "Give me one hundred preachers who fear nothing but sin and desire nothing but God, and I care not whether they be clergymen or laymen, they alone will shake the gates of Hell and set up the kingdom of Heaven upon Earth." - John Wesley

  8. #8
    Join Date
    Jan 2004
    Posts
    66,446
    Plugin Contributions
    81

    Default Re: Report on return customers

    Quote Originally Posted by 0be1 View Post
    Thanks Dr. Byte... but can the query be re-written to work in 4.0
    No.
    But you can run this query and dump it into Excel and count the duplicate values, and work out the percentages from there:
    Code:
    SELECT count(orders_id) AS numorders 
    FROM  orders GROUP BY customers_id;
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  9. #9
    Join Date
    Jan 2004
    Posts
    482
    Plugin Contributions
    0

    Default Re: Report on return customers

    Thank you, DrByte!! This gives us a wealth of information! :)

    Quote Originally Posted by DrByte View Post
    This may look odd, but it should work as-is, on MySQL 5.0 or greater:
    Code:
    SET @custcount=0;
    SELECT (@custcount:=count(*)) as custcount 
    FROM customers;
    SELECT numorders, count(numorders) as numcusts, @custcount as totalcustomers, count(numorders)/@custcount as percent
    FROM (SELECT count(orders_id) AS numorders 
    FROM  orders GROUP BY customers_id) o
    GROUP BY (o.numorders) ORDER BY numorders DESC;
    If you're using custom table prefixes, you'll need to add your prefix to the two highlighted tablenames.

 

 

Similar Threads

  1. v150 Customers Referral Report
    By CnTGifts in forum General Questions
    Replies: 3
    Last Post: 9 Nov 2012, 07:08 PM
  2. Return Items to Customers Cart
    By cowspot in forum General Questions
    Replies: 0
    Last Post: 16 Oct 2009, 03:32 AM
  3. Customers Referral Report - UK
    By voddie in forum General Questions
    Replies: 3
    Last Post: 12 Nov 2006, 07:50 AM
  4. Adding Progress Report for Customers
    By yuchien in forum Customization from the Admin
    Replies: 1
    Last Post: 19 Oct 2006, 08:40 PM

Posting Permissions

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