Zen Cart Logo
Forums / General Questions / Report on return customers

Report on return customers

Locked

Views: 1,223

Results 1 to 9 of 9
This thread is locked. New replies are disabled.
4 Mar 2008, 6:05 AM
#1
emtecmedia avatar

emtecmedia

Zen Follower

Join Date:
May 2005
Posts:
108
Plugin Contributions:
0

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.

4 Mar 2008, 8:13 AM
#2
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Report on return customers

This may look odd, but it should work as-is, on MySQL 5.0 or greater:```
SET @custcount=0;
SELECT (@custcount:=count(*)) as custcount
FROM [B]customers[/B];
SELECT numorders, count(numorders) as numcusts, @custcount as totalcustomers, count(numorders)/@custcount as percent
FROM (SELECT count(orders_id) AS numorders
FROM [B]orders[/B] GROUP BY customers_id) o
GROUP BY (o.numorders) ORDER BY numorders DESC;

4 Mar 2008, 10:47 PM
#3
emtecmedia avatar

emtecmedia

Zen Follower

Join Date:
May 2005
Posts:
108
Plugin Contributions:
0

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.

5 Mar 2008, 3:20 AM
#4
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Report on return customers

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

5 Mar 2008, 2:58 PM
#5
0be1 avatar

0be1

Totally Zenned

Join Date:
Sep 2004
Location:
Murfreesboro, TN
Posts:
479
Plugin Contributions:
0

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

5 Mar 2008, 5:36 PM
#6
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

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.

5 Mar 2008, 10:55 PM
#7
0be1 avatar

0be1

Totally Zenned

Join Date:
Sep 2004
Location:
Murfreesboro, TN
Posts:
479
Plugin Contributions:
0

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 :D

0be1

6 Mar 2008, 6:14 AM
#8
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Report on return customers

0be1:

Thanks Dr. Byte... but can the query be re-written to work in 4.0No.
But you can run this query and dump it into Excel and count the duplicate values, and work out the percentages from there:

SELECT count(orders_id) AS numorders 
FROM  orders GROUP BY customers_id;
29 Jun 2008, 4:01 PM
#9
ksoup avatar

ksoup

Zen Follower

Join Date:
Jan 2004
Posts:
413
Plugin Contributions:
1

Re: Report on return customers

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

DrByte:

This may look odd, but it should work as-is, on MySQL 5.0 or greater:```
SET @custcount=0;
SELECT (@custcount:=count(*)) as custcount
FROM [B]customers[/B];
SELECT numorders, count(numorders) as numcusts, @custcount as totalcustomers, count(numorders)/@custcount as percent
FROM (SELECT count(orders_id) AS numorders
FROM [B]orders[/B] GROUP BY customers_id) o
GROUP BY (o.numorders) ORDER BY numorders DESC;