The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Databases
> Oracle Development
|
Run a Count on a portion of a Date
Discuss Run a Count on a portion of a Date in the Oracle Development forum on Dev Shed. Run a Count on a portion of a Date Oracle Development forum discussing administration, Oracle queries, and other Oracle-related topics. Oracle is known as one of the most robust multi-platform relational databases available.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

August 30th, 2012, 03:53 PM
|
|
Registered User
|
|
Join Date: Aug 2012
Posts: 2
Time spent in forums: 9 m 12 sec
Reputation Power: 0
|
|
|
Run a Count on a portion of a Date
Hey all,
I am trying to run a query that will count the number of each occurrence of a combined month and day.
Birthdays are formatted as: 1947-07-26 00:00:00
I need to query everyone in the system who share the same month & day, but not year & time. For example:
1927-07-26 00:00:00
1927-07-26 00:00:00
1987-07-26 00:00:00
1965-07-26 00:00:00
1981-03-14 00:00:00
would give me a Count of 4 for 7/26 and a Count of 1 for 3/14
|

August 30th, 2012, 08:37 PM
|
 |
SQL Consultant
|
|
Join Date: Feb 2003
Location: Toronto Canada
|
|
Code:
SELECT MONTH(thedate)
, DAY(thedate)
, COUNT(*)
FROM daTable
GROUP
BY MONTH(thedate)
, DAY(thedate)
|

August 31st, 2012, 09:11 AM
|
|
Registered User
|
|
Join Date: Aug 2012
Posts: 2
Time spent in forums: 9 m 12 sec
Reputation Power: 0
|
|
|
Error: ORA-00904: "DAY": invalid identifier
(State:S0022, Native Code: 388)
DBMS OUTPUT
-----------
”
|

August 31st, 2012, 09:15 AM
|
 |
SQL Consultant
|
|
Join Date: Feb 2003
Location: Toronto Canada
|
|
Quote: | Originally Posted by Prolific Error: ORA-00904 | please allow me to point out that you posted an oracle problem in the mysql forum
i shall now move your thread to the oracle forum
you could also, you know, just look up in the oracle manual the equivalent to the MONTH() and DAY() functions that are specific to oracle
|

August 31st, 2012, 11:24 AM
|
 |
Contributing User
|
|
Join Date: Apr 2012
Location: spaceBAR Central
|
|
This is one way to give you the count by month/day:
Code:
select to_char( birth_date, 'mm-dd' ) as birth_day, count(*)
from schema.table
group by to_char( birth_date, 'mm-dd' )
|

August 31st, 2012, 11:37 AM
|
 |
Contributing User
|
|
Join Date: Apr 2012
Location: spaceBAR Central
|
|
And if you wanted to only count people born in July(07)/1977:
Code:
select to_char( birth_date, 'mm-dd' ) as birth_day, count(*)
from schema.table
where birth_date between to_date( '07-01-1977','mm-dd-yyyy' )
and to_date( '07-31-1977','mm-dd-yyyy' )
group by to_char( birth_date, 'mm-dd' )
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|