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
 
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 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 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
No new posts find RACF group for access to spooled... jzhardy JCL & VSAM 1 Mon May 08, 2017 11:46 am

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