Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
Is it possible to group by year & month in DB2

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
Cketha
Warnings : 1

New User


Joined: 19 May 2007
Posts: 22
Location: mumbai

PostPosted: Wed Jun 06, 2007 6:22 pm    Post subject: Is it possible to group by year & month in DB2
Reply with quote

Hi,
I have field in DB2 table defined with Date as a data type, it's having daily details like
2007-29-01
2007-20-01
2007-30-01,
2007-31-02
2007-31-02

in CCYY-DD-MM format

Is it possible to group by year & month without considering the DD
We want only one record per month.
Can you help regarding this?
Back to top
View user's profile Send private message

Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Wed Jun 06, 2007 6:46 pm    Post subject: Re: Group by month in DB2
Reply with quote

Cketha wrote:
Hi,
I have field in DB2 table defined with Date as a data type, it's having daily details like
2007-29-01
2007-20-01
2007-30-01,
2007-31-02
2007-31-02

in CCYY-DD-MM format

Is it possible to group by year & month without considering the DD
We want only one record per month.
Can you help regarding this?


You can do it with
Code:
SELECT YEAR_MONTH, SUM(AMOUNT) FROM
(SELECT SUBSTR(CHAR(DATE_COLUMN,ISO),1,7) AS YEAR_MONTH, AMOUNT FROM TABLE)
GROUP BY YEAR_MONTH
Back to top
View user's profile Send private message
Cketha
Warnings : 1

New User


Joined: 19 May 2007
Posts: 22
Location: mumbai

PostPosted: Wed Jun 06, 2007 6:52 pm    Post subject: Re: Group by month in DB2
Reply with quote

Craq Giegerich wrote:
Cketha wrote:
Hi,
I have field in DB2 table defined with Date as a data type, it's having daily details like
2007-29-01
2007-20-01
2007-30-01,
2007-31-02
2007-31-02

in CCYY-DD-MM format

Is it possible to group by year & month without considering the DD
We want only one record per month.
Can you help regarding this?


You can do it with
Code:
SELECT YEAR_MONTH, SUM(AMOUNT) FROM
(SELECT SUBSTR(CHAR(DATE_COLUMN,ISO),1,7) AS YEAR_MONTH, AMOUNT FROM TABLE)
GROUP BY YEAR_MONTH


Thank you.
It will work.
Back to top
View user's profile Send private message
Abirami.YN

New User


Joined: 16 Jul 2005
Posts: 15
Location: India - Chennai

PostPosted: Thu Jun 07, 2007 3:05 pm    Post subject:
Reply with quote

Hi

I am getting error for the above query. Error Message is

DSNT408I SQLCODE = -104, ERROR: ILLEGAL SYMBOL "<EMPTY>". SOME SYMBOLS THAT
MIGHT BE LEGAL ARE: CORRELATION NAME
DSNT418I SQLSTATE = 42601 SQLSTATE RETURN CODE
DSNT415I SQLERRP = DSNHSM10 SQL PROCEDURE DETECTING ERROR
DSNT416I SQLERRD = 0 0 0 -1 471 0 SQL DIAGNOSTIC INFORMATION
DSNT416I SQLERRD = X'00000000' X'00000000' X'00000000' X'FFFFFFFF'
X'000001D7' X'00000000' SQL DIAGNOSTIC INFORMATION


My Query:

SELECT YY1MM, SUM(PURCHASE_AMT)
FROM (SELECT SUBSTR(CHAR(ARCH_DATE,ISO),1,7) AS YY1MM,
PURCHASE_AMT FROM PURTBL)
GROUP BY YY1MM;


Could you plz help me.

Thank You.
Back to top
View user's profile Send private message
Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Thu Jun 07, 2007 3:21 pm    Post subject:
Reply with quote

Quote:
SELECT YY1MM, SUM(PURCHASE_AMT)
FROM (SELECT SUBSTR(CHAR(ARCH_DATE,ISO),1,7) AS YY1MM,
PURCHASE_AMT FROM PURTBL)
GROUP BY YY1MM;

try
Code:
SELECT YY1MM, SUM(PURCHASE_AMT)
FROM (SELECT SUBSTR(CHAR(ARCH_DATE,ISO),1,7) AS YY1MM,
PURCHASE_AMT FROM PURTBL) x
GROUP BY YY1MM;
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Increment number for every group of r... srajendran2 DFSORT/ICETOOL 7 Thu Nov 09, 2017 10:31 pm
This topic is locked: you cannot edit posts or make replies. Can a alphanumeric data be moved to a... nico_neoz COBOL Programming 10 Mon Oct 30, 2017 8:28 am
No new posts Fetch Previous month & year in MM... girishb2 DFSORT/ICETOOL 3 Thu Sep 21, 2017 9:54 pm
No new posts column with count of rows within dist... ronald wouterson DB2 4 Sun Sep 17, 2017 9:48 pm
This topic is locked: you cannot edit posts or make replies. Limit access to certain RACF group cvnlynn CLIST & REXX 5 Wed Aug 23, 2017 2:28 am

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us