INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Query for Best Sales Day?

Query for Best Sales Day?

(OP)
I am confused how I can write a query to return the best sales day in terms of the amount and the date.

Table: sales
date field: dateStamp
price: price

My attempt did not work:

CODE

SELECT count(*) as totalSales, dateStamp
FROM sales
GROUP BY dateStamp
ORDER BY price desc Limit 1 

RE: Query for Best Sales Day?

Hi

Are you sure you want to order by price and not by totalSales ?

Feherke.
feherke.ga

RE: Query for Best Sales Day?

(OP)
Thanks Feherke

I changed it to this:

CODE -->

SELECT count(*) as totalSales, dateStamp
FROM sales
GROUP BY dateStamp
ORDER BY totalSales desc Limit 1 

This is what it returned:
totalSales: 7 | dateStamp: 2012-10-21 07:33:25

I know my record sales day is higher than 7.

Do you think it could be how the date is formatted that is returning a smaller set of sales?

RE: Query for Best Sales Day?

Count? Really?

SELECT SUM(price) as totalSales, dateStamp
FROM sales
GROUP BY dateStamp
ORDER BY SUM(price) desc Limit 1 
 

Skip,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

RE: Query for Best Sales Day?

Hi

Quote (DrumAt5280)

date field: dateStamp
You wrote date, so I just let you group by it... But looks like there you got the second with the most activity.

Just date() it :

CODE --> MySQL

SELECT count(*) as totalSales, date(dateStamp)
FROM sales
GROUP BY date(dateStamp)
ORDER BY totalSales desc Limit 1 

Feherke.
feherke.ga

RE: Query for Best Sales Day?

(OP)
Thanks guys, much appreciated, that worked great!

RE: Query for Best Sales Day?

What really is most important is the profit, isn't it?

CODE

SELECT Sum(price-cost) as totalProfit, date(dateStamp)
FROM sales
GROUP BY date(dateStamp)
ORDER BY totalProfit desc Limit 1 


Anyway, this would need every sales item to be tagged with a cost (production cost, acquisition value, time effort, ...) and not only a price.

Bye, Olaf.

RE: Query for Best Sales Day?

If you only want the largest sales value.

CODE --> SQL

SELECT MAX(totalSales), date(dateStamp)  FROM sales; 

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close