Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query for Best Sales Day? 1

Status
Not open for further replies.

DrumAt5280

Technical User
Sep 8, 2003
194
US
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
 
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?
 
Count? Really?

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

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
Hi

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

Just [tt]date()[/tt] it :
Code:
[b]SELECT[/b] count[teal](*)[/teal] [b]as[/b] totalSales[teal],[/teal] [maroon]date[/maroon][teal]([/teal]dateStamp[teal])[/teal]
[b]FROM[/b] sales
[b]GROUP BY[/b] [maroon]date[/maroon][teal]([/teal]dateStamp[teal])[/teal]
[b]ORDER BY[/b] totalSales [b]desc Limit[/b] [purple]1[/purple]

Feherke.
feherke.ga
 
Thanks guys, much appreciated, that worked great!
 
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.
 
If you only want the largest sales value.

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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top