Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups 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 Reg:Displaying the particular month o... bhavana yalavarthi All Other Mainframe Topics 4 Sat Jul 08, 2017 8:13 pm
No new posts find RACF group for access to spooled... jzhardy JCL & VSAM 1 Mon May 08, 2017 11:46 am
No new posts Group Data based on a key Arun Raj DFSORT/ICETOOL 7 Thu Apr 27, 2017 11:29 pm
No new posts Need Help with : IFTHEN(WHEN=GROUP) Sumanta_89 DFSORT/ICETOOL 1 Wed Apr 19, 2017 5:23 pm
No new posts Group elements using ICETOOL Learncoholic DFSORT/ICETOOL 2 Fri Apr 14, 2017 11:01 am


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us