Reply
GROUP BY "Year" using field with full date
Old 11-12-2008, 10:48 AM GROUP BY "Year" using field with full date
ChipJohns's Avatar
I don't know! Do you?

Posts: 489
Name: Chip Johns
Location: Savannah Georgia
Trades: 0
GROUP BY scenario.

I am trying to figure out how I can group records by year, i.d.,

2007 - 25,000
2008 - 15,000

And the date filed has full date - mm/dd/yyyy

Is there a way to accomplish this?

Thanks for any help

~Chip
ChipJohns is offline
Reply With Quote
View Public Profile Visit ChipJohns's homepage!
 
 
When You Register, These Ads Go Away!
Old 11-12-2008, 11:27 AM Re: GROUP BY "Year" using field with full date
tripy's Avatar
Do not try this at home!

Posts: 3,176
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
If you just want to fetch the total, this should do it:
Code:
select count(*)
from table
group by date(date_field)
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is online now
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 11-12-2008, 11:31 AM Re: GROUP BY "Year" using field with full date
chrishirst's Avatar
Super Moderator

Posts: 22,224
Location: Blackpool. UK
Trades: 0
Not sure if access supports DATEPART() but try;

GROUP BY DATEPART("yyyy", date_column)
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Growing old is mandatory - Growing up is optional
Code Samples | People Counting System | Bits & Bobs
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 11-12-2008, 11:40 AM Re: GROUP BY "Year" using field with full date
ChipJohns's Avatar
I don't know! Do you?

Posts: 489
Name: Chip Johns
Location: Savannah Georgia
Trades: 0
Thanks for the quick reply Chris. I'll try this. I'll let you know if it works with access.
ChipJohns is offline
Reply With Quote
View Public Profile Visit ChipJohns's homepage!
 
Old 11-12-2008, 11:48 AM Re: GROUP BY "Year" using field with full date
tripy's Avatar
Do not try this at home!

Posts: 3,176
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Hum, my bad... I did not checked for which db.
My solution is only valid for mysql/postgresql.
Sorry.
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is online now
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 11-12-2008, 12:12 PM Re: GROUP BY "Year" using field with full date
ChipJohns's Avatar
I don't know! Do you?

Posts: 489
Name: Chip Johns
Location: Savannah Georgia
Trades: 0
Didn't work with access. It grouped by the full date.

I think I might just add another field that is specifically the Year. Then use this to group by. IN the long run it will probably be quicker..!

Any thoughts?

Thanks,

Chip
ChipJohns is offline
Reply With Quote
View Public Profile Visit ChipJohns's homepage!
 
Old 11-12-2008, 01:37 PM Re: GROUP BY "Year" using field with full date
Learning Newbie's Avatar
Defies a Status

Latest Blog Post:
Astounding Republican Paranoia
Posts: 5,674
Name: John Alexander
Trades: 0
Group By Format(dateValue, "yyyy")
Learning Newbie is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to GROUP BY "Year" using field with full date
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 



Page generated in 0.13210 seconds with 13 queries