SunQuest
 
           MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMySQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old May 10th, 2004, 04:25 PM
Spongy's Avatar
Spongy Spongy is offline
Alternately High
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Location: Hilversum, Netherlands
Posts: 223 Spongy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 56 m 41 sec
Reputation Power: 5
Send a message via MSN to Spongy
MySQL maximum counting values

Hello everybody!

I got a small problem with MySQL. As the title says, I want to get the maximum values from a count.
What I tried is the following:
Code:
SELECT date, COUNT(*) AS counted FROM counter GROUP BY date 

This retrieves my data just as it's supposed to do. But now I want to get the MAX of all the data...
I didn't know exactly what to do. I tried to do this:
Code:
SELECT date, MAX(COUNT(*)) AS max_count FROM counter GROUP BY date

Obviously, this didn't work.
Can anybody tell me if I'm on the right track with this one? For more explanation, what I want to do is show the best visited day for my users. Just for fun, maybe there's a PHP-solution for it, but I try to do it with MySQL. I try to learn as much as I can and I think it is possible...

Thnx for the help in advance!

Cheers,
__________________
Work to live, don't live to work

Reply With Quote
  #2  
Old May 11th, 2004, 04:21 PM
michlmann michlmann is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 56 michlmann User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Try

SELECT count(*) as max_count FROM counter

Reply With Quote
  #3  
Old May 12th, 2004, 06:06 AM
Spongy's Avatar
Spongy Spongy is offline
Alternately High
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Location: Hilversum, Netherlands
Posts: 223 Spongy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 56 m 41 sec
Reputation Power: 5
Send a message via MSN to Spongy
Thnx for the reply, but I think you didn't understand my question very well.
I don't want to retrieve the total number of records of my table, I want the total of one day.
Example:
When I want to get a list of my visitors a day, I can do this:
Code:
SELECT date, COUNT(*) AS counted FROM counter GROUP BY date

That does the trick. But now I only want to show the day with the highest number of visitors. Or in other words, I want the max of the counted fields.

Cheers,

Reply With Quote
  #4  
Old May 16th, 2004, 11:05 AM
michlmann michlmann is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 56 michlmann User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Oh, I see. The following should do the trick:

Code:
 SELECT max(counted) AS max_counted FROM (
   SELECT count(*) AS counted FROM counter GROUP BY date
 )
 

Reply With Quote
  #5  
Old May 16th, 2004, 05:25 PM
Spongy's Avatar
Spongy Spongy is offline
Alternately High
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Location: Hilversum, Netherlands
Posts: 223 Spongy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 56 m 41 sec
Reputation Power: 5
Send a message via MSN to Spongy
Hmm... it didn't...
This is my error:

You have an error in your SQL syntax near 'SELECT COUNT(*) AS counted FROM counter GROUP BY date)' at line 1

Thanks for the help though! I really appreciate it. I hope you have more ideas.

Cheers,

Reply With Quote
  #6  
Old May 17th, 2004, 09:44 AM
michlmann michlmann is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 56 michlmann User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Seems as if your DBS doesn't support subqueries. Create a view and select from the view

CREATE VIEW view_counts AS SELECT date, count(*) AS counted FROM counter GROUP BY date

SELECT max(counted) FROM view_counts;

Reply With Quote
  #7  
Old May 18th, 2004, 01:59 PM
Spongy's Avatar
Spongy Spongy is offline
Alternately High
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Location: Hilversum, Netherlands
Posts: 223 Spongy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 56 m 41 sec
Reputation Power: 5
Send a message via MSN to Spongy
Hmm, didn't work either. Maybe it's time for a MySQL-update... :P

Thnx for the help, but I'll try it with PHP then.

Reply With Quote
  #8  
Old July 21st, 2004, 04:06 AM
jiriczech jiriczech is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 1 jiriczech User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
You know what...

Try to use ORDER BY xxx DESC and LIMIT 1...

Reply With Quote
  #9  
Old July 21st, 2004, 06:33 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
select date, count(date) as thecount from counter GROUP BY date ORDER BY thecount DESC LIMIT 1
__________________
Please don't PM me asking for solutions outside the scope of a thread.
Keeping all responses in a thread stands to help others who come along later,
which is after all what this forum's all about.

Reply With Quote
  #10  
Old February 10th, 2005, 06:45 AM
anjanesh anjanesh is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Location: Trivandrum, Kerala, India
Posts: 3 anjanesh User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 43 m 37 sec
Reputation Power: 0
MAX-CONCAT trick

Same requirement here - MAX(COUNT(`columnname`))
It seems theres a method in MySQL 4.0 to have the MAX in a group solved using some "MAX-CONCAT trick" ?
But Im not able to get the MAX(COUNT()). Anyone can derive it from : http://dev.mysql.com/doc/mysql/en/example-maximum-column-group-row.html ?
Thanks

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > MySQL maximum counting values


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway