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 

SQL Query Help Needed?

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


Joined: 29 Jun 2004
Posts: 106
Topics: 41
Location: Bangalore, INDIA

PostPosted: Tue Apr 17, 2007 8:57 am    Post subject: SQL Query Help Needed? Reply with quote

HI Board,
I have the data in Table-A(Fields: F1, F2, F3) and Table-B(Fields:Q1,Q2) like below:

Table-A
---------
Code:
F1        F2     F3
=         ===    =====
A         ABC    ABCD
A         XYZ    XYZA
A         PQR    PQRS
B         CCC    CCCC
B         DDD    DDDD

Table-B
---------
Code:

Q1       Q2
==       ======
A        NNNNNNNN
B        LLLLLLLLLLL
C        JJJJJJJJJJJJ

I want to the data like below:
Code:

Q2              F1      Count
===========     ==      =====
NNNNNNNN        A        3
LLLLLLLLLLL     B        2


Count is the No of rows in Table-A for each type
Please anybody can help me in writing the SQL Query?
_________________
Best Regards,
----------------
Rammohan Pabba
Software Engineer
Back to top
View user's profile Send private message Send e-mail
kolusu
Site Admin
Site Admin


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

PostPosted: Tue Apr 17, 2007 9:10 am    Post subject: Reply with quote

ramu_mohan21,

Unless I am missing something , this is a simple query. Try this untested solution

Code:

SELECT B.Q2         
      ,A.F1         
      ,COUNT(*)     
  FROM Table1 A         
      ,Table2 B         
 WHERE A.F1  = B.Q1
 GROUP BY B.Q2     
         ,A.F1     
         ; 


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
ramu_mohan21
Beginner


Joined: 29 Jun 2004
Posts: 106
Topics: 41
Location: Bangalore, INDIA

PostPosted: Tue Apr 17, 2007 9:56 am    Post subject: Reply with quote

HI Kolusu,

I have already tried as you mentioned above. At that time I have below error:

DSNT408I SQLCODE = -122, ERROR: A SELECT STATEMENT WITH NO GROUP BY CLAUSE CONTAINS A COLUMN NAME AND AN AGGREGATE FUNCTION IN THE SELECT CLAUSE OR A COLUMN NAME IS CONTAINED IN THE SELECT CLAUSE BUT NOT IN THE GROUP BY CLAUSE
_________________
Best Regards,
----------------
Rammohan Pabba
Software Engineer
Back to top
View user's profile Send private message Send e-mail
kolusu
Site Admin
Site Admin


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

PostPosted: Tue Apr 17, 2007 10:14 am    Post subject: Reply with quote

ramu_mohan21,

If you run the query as is then you will NOT get the -122 error. I am selecting 2 columns and those 2 columns are present in my GROUP by clause. You must be running a different query. Run the query as is shown above in spufi/qmf and shows us the error messages if you get any

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


Joined: 29 Jun 2004
Posts: 106
Topics: 41
Location: Bangalore, INDIA

PostPosted: Wed Apr 18, 2007 1:02 am    Post subject: Reply with quote

You are right. I wrote a wrong SQL Query. I didn't keep B.Q2 in GROUP BY Clause. Now it is working fine.

Thank you for your immediate answer.
_________________
Best Regards,
----------------
Rammohan Pabba
Software Engineer
Back to top
View user's profile Send private message Send e-mail
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