Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > PHP Databases
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
PHP Databases Using PHP in conjunction with databases. PHP questions not specific to databases should be directed to one of the other PHP forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP Databases section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 21st, 2003, 12:58 AM
Authorized User
 
Join Date: Oct 2003
Location: KL, wilayah persekutuan, Malaysia.
Posts: 91
Thanks: 0
Thanked 0 Times in 0 Posts
Default how to select Max

i successfully list out the customer that buy my product every month using mysql. But i can't list out the customer that have the highest sales for every month. please help. Below are my sql command.

select month(s.sales_date), s.cust_id, sum((p.prod_price * sd.quantity)) as Total
from product p, sales_detail sd, sales s, category c
where sd.sales_id=s.sales_id and p.prod_id=sd.prod_id and c.category_id=p.prod_cat and year(s.sales_date) = '1999'
group by month(s.sales_date), s.cust_id;

+---------------------+---------+-------+
| month(s.sales_date) | cust_id | Total |
+---------------------+---------+-------+
| 1 | C001 | 134 |
| 1 | C004 | 162 |
| 2 | C001 | 390 |
| 2 | C020 | 354 |
| 3 | C001 | 522 |
| 3 | C002 | 153 |
| 3 | C013 | 93 |
| 3 | C014 | 50 |
| 3 | C020 | 321 |
| 4 | C001 | 493 |
| 4 | C012 | 33 |
| 4 | C013 | 36 |
| 4 | C014 | 197 |
| 5 | C010 | 487 |
| 5 | C011 | 461 |
| 5 | C020 | 430 |
| 6 | C001 | 667 |
| 6 | C020 | 289 |
| 7 | C001 | 44 |
| 7 | C019 | 178 |
| 7 | C020 | 78 |
| 8 | C001 | 125 |
| 9 | C001 | 144 |
| 9 | C002 | 78 |
| 9 | C003 | 36 |
| 10 | C001 | 250 |
| 10 | C018 | 304 |
| 10 | C019 | 210 |
| 10 | C020 | 308 |
| 11 | C001 | 346 |
| 11 | C020 | 68 |
| 12 | C001 | 203 |
| 12 | C002 | 220 |
|+---------------------+---------+-------+

i try to code this way but to no avail.please help
select month(s.sales_date), s.cust_id, Max(sum((p.prod_price * sd.quantity))) as Total
from product p, sales_detail sd, sales s, category c
where sd.sales_id=s.sales_id and p.prod_id=sd.prod_id and c.category_id=p.prod_cat and year(s.sales_date) = '1999'
group by month(s.sales_date), s.cust_id;




Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
select Max 2 rows for each ID veeruu SQL Language 1 January 31st, 2006 05:08 AM
Select two MAX record per each veeruu SQL Language 2 January 23rd, 2006 12:57 AM
How to select 5th Max in a Table ramk_1978 SQL Language 2 December 30th, 2004 01:41 AM
Ani 1 noe how to retrieve record from select max() babymeizi Pro JSP 2 October 14th, 2004 05:11 PM
How to select Max hosefo81 MySQL 0 November 25th, 2003 10:27 PM



All times are GMT -4. The time now is 02:17 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.