I’ve been wrestling with this for a while now. I’m not sure MYSQL query is the best way to do this but I’m at a loss.
I have entries for certain people on certain dates, however they won’t always be on the same date. Eg:
Person Date Product
Mike 2012/12/1 Pants
Chris 2012/12/4 Shoes
Mike 2012/12/4 Pants
Julian 2012/12/5 Hat
I am using this table for trending reports and I need to select a date range, example 2012/12/2 – 2012/12/10. I need a table that shows what each person was wearing each day so I can see what percentage is being worn on any given day. The output table would look something like this:
Person Date Product
Mike 2012/12/1 Pants
Mike 2012/12/2 Pants
Mike 2012/12/3 Pants
Chris 2012/12/4 Shoes
Mike 2012/12/4 Shoes
Julian 2012/12/5 Hat
Mike 2012/12/5 Shoes
Chris 2012/12/5 Shoes
Julian 2012/12/6 Hat
Mike 2012/12/6 Shoes
Chris 2012/12/6 Shoes
Julian 2012/12/7 Hat
Mike 2012/12/7 Shoes
Chris 2012/12/7 Shoes
And so forth…. depending on the date range. Ideally a table like this would be even better:
Date Product Worn Total
2012/12/1 Pants 1 1
2012/12/1 Shoes 0 1
2012/12/1 Hat 0 1
2012/12/2 Pants 1 1
2012/12/2 Shoes 0 1
2012/12/2 Hat 0 1
2012/12/3 Pants 1 1
2012/12/3 Shoes 0 1
2012/12/3 Hat 0 1
2012/12/4 Pants 0 2
2012/12/4 Shoes 2 2
2012/12/4 Hat 0 2
2012/12/4 Pants 0 3
2012/12/4 Shoes 2 3
2012/12/4 Hat 1 3
I’m currently working in PHP using a MySql DB. Any thoughts, suggestions are appreciated.
pseudocode mostly:
It’s probably not the most efficient way to get it but it should get you the data you need. Put in some TR’s and TD’s, wrap it in a table and you should have what you are looking for.