|
-
Jun 6th, 2000, 06:41 PM
#1
Thread Starter
Fanatic Member
I have a table called Work_History and in it a field called Work_Date.
How can I get hold of the Work_Date which occurs most often?
-
Jun 6th, 2000, 07:17 PM
#2
Frenzied Member
SELECT COUNT(Work_Date) AS Total, Work_Date FROM
Work_History GROUP BY Work_Date
ORDER BY Total DESC
- the most common work_date would appear at the top of the returned recordset.
'Buzby'
Visual Basic Developer
"I'm moving to Theory. Everything works there."
-
Jun 6th, 2000, 08:37 PM
#3
Thread Starter
Fanatic Member
When I use that SQL statement, it complains and seems to be waiting for me to pass in a value for Total.
Any ideas?
-
Jun 6th, 2000, 08:40 PM
#4
Frenzied Member
Just do
SELECT COUNT(Work_Date), Work_Date
FROM Work_History GROUP BY Work_Date
ORDER BY COUNT(Work_Date) DESC
The Total bit was just to make it look tidier.
'Buzby'
Visual Basic Developer
"I'm moving to Theory. Everything works there."
-
Jun 6th, 2000, 08:49 PM
#5
Thread Starter
Fanatic Member
Cheers, works a treat.
-
Jun 7th, 2000, 09:14 AM
#6
PowerPoster
Select TOP n record
You also use the SELECT...TOP n sql statement as well to perform you task.
Where n is occurs most offen Work_Date in your databse. Exmaple, over here I put 5 that mean I wish to retrieve the top5 Work_Date that occurs most offen.
Code:
SELECT TOP 5 Work_Date FROM Work_History WHERE Work_Date <> "";
-
Jun 7th, 2000, 05:02 PM
#7
Frenzied Member
TOP [x] doesn't work in all flavours of SQL. If only it did!
'Buzby'
Visual Basic Developer
"I'm moving to Theory. Everything works there."
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|