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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.