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
 

 

Nested Group by SQL - Help Needed

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

New User


Joined: 19 Mar 2008
Posts: 12
Location: India

PostPosted: Thu Aug 07, 2008 10:55 am    Post subject: Nested Group by SQL - Help Needed
Reply with quote

Hi All,
I have 3 columns in my table

Code Mktcode Id
1 10 0001
2 20 0010
3 30 0012
4 40 0013
1 20 0014
.....

so there can be many Ids with the following Code(1,2,3,4) and Mktcode(10,20,30,40).

Currently, i have performed to make a count on Each status code Group by status code by using the below SQL,

SELECT STATUS_CD,COUNT(STATUS_CD)
FROM Table GROUP BY STATUS_CD
Result:
1 2
2 1
3 1
4 1

But Unfortunately i have make the count on status code based on the market code

Expecting result:
010
1 1
2 0
3 0
4 0
020
1 1
2 1
3 0
4 0
030
1 0
2 0
3 1
4 0
040
1 0
2 0
3 0
4 1

Can someone please help me on this to get my desired value!!!
Back to top
View user's profile Send private message

Suresh Ponnusamy

Active User


Joined: 22 Feb 2008
Posts: 107
Location: New York

PostPosted: Thu Aug 07, 2008 7:11 pm    Post subject:
Reply with quote

Your Expecting result is confusing.. What is first column and second column representing here...

If you want to make the count on status code based on the market code
then the result should be as follows rite.. please confirm.

Market Code Status Code Count
10 - 1
20 - 2
30 - 1
40 - 1
Back to top
View user's profile Send private message
mkarthikeyan

New User


Joined: 07 Aug 2008
Posts: 34
Location: Bangalore

PostPosted: Fri Aug 08, 2008 9:04 pm    Post subject: Reply to: Nested Group by SQL - Help Needed
Reply with quote

Group the two columns MKTCODE & STATUS_CD

SELECT MKTCODE,STATUS_CD,COUNT(STATUS_CD) AS CNT
FROM Table GROUP BY MKTCODE,STATUS_CD

The result would be

MKTCODE--STATUS--CNT
10--1--1
20--1--1
20--2--1
30--3--1
40--4--1

Thanks
karthikeyan m

[S/360] was the biggest, riskiest decision I ever made, and I agonized about it for weeks,but deep down I believed there was nothing IBM couldn't do.

- Tom Watson, Jr. IBM Chairman and CEO 1961-1971
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 Sorting group data rajella DFSORT/ICETOOL 3 Sun Jan 22, 2017 11:32 pm
No new posts Syncsort Help to group fields sudhakarraju SYNCSORT 6 Thu Dec 29, 2016 1:38 am
No new posts abend sort based on count records in ... anatol DFSORT/ICETOOL 5 Mon Oct 17, 2016 10:10 pm
No new posts Get Record count in summary record fo... Atul Banke DFSORT/ICETOOL 21 Fri Sep 23, 2016 4:17 pm
No new posts Help Needed with View Direct shailesh_do CA Products 2 Wed Jul 13, 2016 10:39 am


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