A Query for Report

From: Date: Mon, 11 Sep 2000 02:33:45 +0000
Subject: A Query for Report
Groups: php.db 
Request: Send a blank email to php-db+get-2779@lists.php.net to get a copy of this message
I am using MySQL 3.22.32, Linux 2.2.16, PHP4.0.1pl2 Let's us one example: my sales table:- salesmancode salesdate my sales table data: A 2000-08-20 A 2000-08-02 B 2000-08-20 B 2000-08-02 A 2000-07-10 B 2000-07-10 B 2000-07-05 B 2000-07-01 My Results should be Salesmancode Jul Aug Total A 1 2 3 B 3 2 5 Total 4 4 8 The actual report would be for the past 12 months. I am not sure if there are any idea for more efficient/simple way. I have 2 solutions now. 1 idea was from John McKown by using PHP programming. John's idea sounds very good and I really appreciate his time for helping me out. I understand the concept behind it but not on some part of the PHP coding. Well give me some comments on my solution. My the other solution is by writing to a temp table. The temp table would have the fields of salesmancode, jan, feb,..,dec,total I would use 12 select statements and write each row 12 times. eg. SELECT salesmancode, count(*) as total from sale where month(saledate)=month("$mth") group by salemancode $mth="2000-08-01" - this will be today's date and count-back 12 months. The above SELECT will give me (for month of aug) salesmancode total A 2 B 2 I will write to my temp table - A = A, total= aug, B = B, total = Aug This method is going to involve a lot of I/O on the hard disk. I would appreciate it if anyone have a solution to this query/report.

« previous php.db (#2779) next »