MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

SPUFI for doing a Unique sub-string Select, and a Count

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
MikeBaker
Beginner


Joined: 04 May 2004
Posts: 96
Topics: 9

PostPosted: Wed Mar 30, 2005 11:55 pm    Post subject: SPUFI for doing a Unique sub-string Select, and a Count Reply with quote

Hi,

If I have the following data:-

Code:

ABBBBBBB
ABBBBBBB
ABEEEEEE
ACCCCCCC
ADDDDDDD
AEEEEEEE
AEEEEEEE
AEFFFFFF
AGGGGGGG


Then I would like to know the SPUFI for selecting every single Unique occurrence and the Total number of occurrences.

So... for the above data, my results would look like:-
Code:

AB = 3
AC = 1
AD = 1
AE = 3
AG = 1


For argument's sake, let's pretend the field name is called "SURNAME".

Many thanks.
Back to top
View user's profile Send private message
s_shivaraj
Beginner


Joined: 21 Sep 2004
Posts: 140
Topics: 14
Location: Chennai, India

PostPosted: Thu Mar 31, 2005 2:08 am    Post subject: Reply with quote

Hi Mike,

Try this

SELECT count(*), left(surname,2) FROM id.tablename group by left(surname,2);

I tried in windows UDB 8.1, but i dont know whether it works in mainframe Db2, please try this and let us know..

Very Happy
_________________
Cheers
Sivaraj S

'Technical Skill is the Master of complexity, while Creativity is the Master of Simplicity'
Back to top
View user's profile Send private message AIM Address
bauer
Intermediate


Joined: 10 Oct 2003
Posts: 315
Topics: 49
Location: Germany

PostPosted: Thu Mar 31, 2005 5:39 am    Post subject: Reply with quote

Hi all,

"group by" with a column function is not allowed (DB2 / OS390, Version 7.2). May be in a newer version ......

So try this:
Code:

SELECT COUNT(*), X
FROM (
 SELECT LEFT(surname,2) X
    FROM id.tablename
     ) AS Y
GROUP BY X


regards,
bauer
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12376
Topics: 75
Location: San Jose

PostPosted: Thu Mar 31, 2005 6:40 am    Post subject: Reply with quote

MikeBaker,

To be precise , try this


Code:

SELECT A.SNAME                         
      ,CHAR('=')                       
      ,COUNT(*) TOT_CNT                 
  FROM(SELECT SUBSTR(SURNAME,1,2) SNAME
         FROM H1)A                     
GROUP BY A.SNAME                       
;                                       


Hope this helps..

Cheers

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
devjfl1
Beginner


Joined: 03 Jan 2003
Posts: 4
Topics: 1
Location: California

PostPosted: Wed Apr 13, 2005 4:08 pm    Post subject: Reply with quote

Kolusu,

I was in need of the same type of query. The SEARCH of your board is very fast and your example worked like a charm.

thanks!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group