Jump to content

Help with MAX function


kevinfwb

Recommended Posts

I have a MySQL database for a chain of restaurants that tracks store sales, among other things.

I have a table called sales that stores

 

storeNum

period

week

year

sales

 

I'm trying to find which store has the max sales for a given period/week/year.

storeNum, period, week and year are all INTS and sales is a double

I have sales set to a double because other fields stores/calculates percentage of increase/decrease etc to the 4th decimal.

 

I can get the code to work using

SELECT MAX(sales) FROM Sales WHERE period=8 AND week=2 AND year=2007

 

However, this doesn't give me the corresponding store number so I tried the following code that returns 0 results.

SELECT sales, storeNum FROM Sales WHERE period=8 AND week=2 AND year=2007 AND sales=(SELECT MAX(sales) FROM Sales)

 

The code doesn't pull any rows for any period, week, or year.

I think I've tried this code in just about every imaginable syntax.  Any help is greatly appreciated.

 

-Kevin

 

Link to comment
https://forums.phpfreaks.com/topic/64774-help-with-max-function/
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.