Jump to content

Using SUM With MAX


dlebowski

Recommended Posts

Hi.  I have a table that looks like the following:

 

+------+---------------+

| Price | ItemNumber |

+------+---------------+

| 1      | 33            |

| 2      | 66            |

| 3      | 66            |

| 4      | 44            |

| 5      | 44            |

| 6      | 44            |

+------+---------------

 

What I want to do is takes the highest Price for each ItemNumber, and sum those values.  For example:

 

1 - 33

3 - 66

6 - 44

---------

Total:  10

 

I am assuming that I am going to use MAX function and SUM, but how do I use both.  Here is my query:

 

SELECT MAX(Price), ItemNumber FROM mytable GROUP BY ItemNumber ORDER BY ItemNumber

 

This query gives me this:

 

1 - 33

3 - 66

6 - 44

---------

 

 

So how do I use that same query to give me a SUM of those values?  Than you in advance!

Link to comment
https://forums.phpfreaks.com/topic/247986-using-sum-with-max/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.