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
 

 

How to group only by year and month in the DB2

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

New User


Joined: 05 Jun 2007
Posts: 28
Location: Mumbai

PostPosted: Fri Jun 08, 2007 12:45 pm    Post subject: How to group only by year and month in the DB2
Reply with quote

Hi,

I am having fields(eff-date) with the data type 'Date' in the DB2 table, I need to group by this field only on the basis of year and month(With out considering the day(d)
. Can you send the query for this

Input
Eff-date (mm/dd/ccyy) amount
01/31/2007 111
01/30/2007 222
01/29/2007 333
02/28/2007 333
02/27/2007 222
02/26/2007 222

Output should be
Eff-date(mm/dd/ccyy) amount
01/01/2007 666
02/01/2007 777


Thanks,
Back to top
View user's profile Send private message

Abirami.YN

New User


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

PostPosted: Fri Jun 08, 2007 1:44 pm    Post subject:
Reply with quote

Hi Bala,

Check the below link

http://ibmmainframes.com/viewtopic.php?t=21605


Regards,
Abirami.
Back to top
View user's profile Send private message
banand

New User


Joined: 05 Jun 2007
Posts: 28
Location: Mumbai

PostPosted: Fri Jun 08, 2007 6:05 pm    Post subject:
Reply with quote

We tired it , but it is not working. That query is giving error.
Can you suggest some other way

Thanks
Back to top
View user's profile Send private message
Abirami.YN

New User


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

PostPosted: Fri Jun 08, 2007 10:12 pm    Post subject:
Reply with quote

Try this below query

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

It's working for me. Let me know what error message or what result you are getting??

Regards,
Abirami.
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Fri Jun 08, 2007 10:16 pm    Post subject:
Reply with quote

Hello Bala,

You will usually gets better replies sooner if when you post something is not working, you also post any diagnostic information available from the failed process.

Good luck icon_smile.gif
Back to top
View user's profile Send private message
banand

New User


Joined: 05 Jun 2007
Posts: 28
Location: Mumbai

PostPosted: Tue Jun 12, 2007 7:15 pm    Post subject:
Reply with quote

Hi

I have tried the below query

SELECT YY1MM, SUM(BID_RT), FK_CURRID
FROM (SELECT SUBSTR(CHAR(CREATION_DT,ISO),1,7) AS YY1MM, FK_CURRID,
BID_RT FROM EXCG) X
GROUP BY YY1MM;

and i got the below error msg

QUERY MESSAGES:
The grouping is inconsistent.


In the table datas are stored like
FK_CURRID CREATION_DT BID_RT
------------- ---------------- ---------
006 05/31/2007 1.06860000
006 05/30/2007 1.07100000
006 05/29/2007 0.00000000

Please help me to solve the error in the query


Thanks
Back to top
View user's profile Send private message
Craq Giegerich

Senior Member


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

PostPosted: Tue Jun 12, 2007 7:53 pm    Post subject:
Reply with quote

banand wrote:
Hi

I have tried the below query

SELECT YY1MM, SUM(BID_RT), FK_CURRID
FROM (SELECT SUBSTR(CHAR(CREATION_DT,ISO),1,7) AS YY1MM, FK_CURRID,
BID_RT FROM EXCG) X
GROUP BY YY1MM;

and i got the below error msg

QUERY MESSAGES:
The grouping is inconsistent.


In the table datas are stored like
FK_CURRID CREATION_DT BID_RT
------------- ---------------- ---------
006 05/31/2007 1.06860000
006 05/30/2007 1.07100000
006 05/29/2007 0.00000000

Please help me to solve the error in the query


Thanks

icon_sad.gif
If you would read about grouping you would find that you need
GROUP BY YY1MM, FK_CURRID
Back to top
View user's profile Send private message
banand

New User


Joined: 05 Jun 2007
Posts: 28
Location: Mumbai

PostPosted: Wed Jun 13, 2007 11:30 am    Post subject:
Reply with quote

Hi

It is working fine, after adding the FK_CURRID field in the Group By Clause.

Thanks a lot


Can I know why we need to add that column in the Query?.

Is it like, other than the column which ever used for the aggregate function should be mention in Group By clause.

Thanks,
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 Syncsort Help to group fields sudhakarraju SYNCSORT 6 Thu Dec 29, 2016 1:38 am
This topic is locked: you cannot edit posts or make replies. How to pass the previous month date i... Suganya87 DFSORT/ICETOOL 5 Mon Oct 31, 2016 4:13 pm
No new posts Wishing everyone a very Happy Diwali ... Rohit Umarjikar General Talk & Fun Stuff 1 Sat Oct 29, 2016 1:54 am
No new posts How to get previous month in SYMNAMES Suganya87 SYNCSORT 9 Fri Oct 28, 2016 1:37 pm
No new posts abend sort based on count records in ... anatol DFSORT/ICETOOL 5 Mon Oct 17, 2016 10:10 pm


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