| |
|
If this is your first visit, be sure to check out the FAQ by clicking the link above.
You may have to register before you can post: click the register link above to proceed.
To start viewing messages, select the forum that you want to visit from the selection below.
|
 |

03-31-04, 10:04
|
|
Registered User
|
|
Join Date: Mar 2004
Posts: 54
|
|
|
query help please!!
|
|
Hi,
I have 2 tables for example EMP and DEPT
EMP DEPT
------- --------
empno deptno
empname dept_name
deptno
job
i want result as all the department names and corresponding
employees count for the given job title.
deptname count
-------- --------
sales 100
accounting 20
research 10
I am not good at SQL, please help me!
Thanks
|
|

03-31-04, 10:15
|
|
Super Moderator
|
|
Join Date: Aug 2001
Location: UK
Posts: 4,534
|
|
|
Re: query help please!!
If you have tried a query and found it throwing errors, please post the same ...
Cheers
Sathyaram
__________________
Visit the new-look IDUG Website , register to gain access to the excellent content.
|
|

03-31-04, 10:33
|
|
Registered User
|
|
Join Date: Mar 2004
Posts: 54
|
|
|
|
I tried
O.K. let me give my actual problem where i am working on.
i have the following tables
CFGHDRLOG CFGSERVICE
-------------- ------------------
MSGID SERVICEID
LOGONID SERVICE_NAME
CHANNELID
SERVICEID
I tried the following query
SELECT SERVICEID, COUNT(*) FROM DB2A.CFGHDRLOG WHERE CHANNELID=3482 GROUP BY SERVICEID
i got the follwing result
SERVICEID 2
--------------- -------
34 2
27 6
20 8
now i want display SERVICE_NAME instead of SERVICEID, which is in CFGSERVICE table?
i coud not figure it out!!!
|
|

03-31-04, 10:43
|
|
:-)
|
|
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
|
|
Quote:
Originally posted by manth
I tried
O.K. let me give my actual problem where i am working on.
i have the following tables
CFGHDRLOG CFGSERVICE
-------------- ------------------
MSGID SERVICEID
LOGONID SERVICE_NAME
CHANNELID
SERVICEID
I tried the following query
SELECT SERVICEID, COUNT(*) FROM DB2A.CFGHDRLOG WHERE CHANNELID=3482 GROUP BY SERVICEID
i got the follwing result
SERVICEID 2
--------------- -------
34 2
27 6
20 8
now i want display SERVICE_NAME instead of SERVICEID, which is in CFGSERVICE table?
i coud not figure it out!!!
|
SELECT LOG.SERVICEID, SVC.SERVICE_NAME, COUNT(*) FROM DB2A.CFGHDRLOG LOG, DB2A.CFGSERVICE SVC WHERE LOG.CHANNELID=3482 AND LOG.SERVICEID = SVC.SERVICEID GROUP BY LOG.SERVICEID
|
|

03-31-04, 10:52
|
|
Registered User
|
|
Join Date: Mar 2004
Posts: 54
|
|
I tried it i am getting the following error
SQL0119N An expression starting with "SERVICE_NAME" specified in a SELECT clause, HAVING clause, or ORDER BY clause is not specified in the GROUP BY clause or it is in a SELECT clause, HAVING clause, or ORDER BY clause with a column function and no GROUP BY clause is specified. SQLSTATE=42803
|
|

03-31-04, 11:15
|
|
:-)
|
|
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
|
|
Quote:
Originally posted by manth
I tried it i am getting the following error
SQL0119N An expression starting with "SERVICE_NAME" specified in a SELECT clause, HAVING clause, or ORDER BY clause is not specified in the GROUP BY clause or it is in a SELECT clause, HAVING clause, or ORDER BY clause with a column function and no GROUP BY clause is specified. SQLSTATE=42803
|
Yes, that's my mistake. The error message is sort of self-explanatory, isn't it? Add "svc.service_name" to the GROUP BY clause.
|
|

03-31-04, 11:29
|
|
Registered User
|
|
Join Date: Mar 2004
Posts: 54
|
|
i did this way as u said
db2 => SELECT LOG.SERVICEID, SVC.SERVICE_NAME, COUNT(*) FROM DB2A.CFGHDRLOG LOG, DB2A.CFGSERVICE SVC WHERE LOG.CHANNELID=3482 AND LOG.SERVICEID = SVC.SERVICEID GROUP BY SVC.SERVICE_NAME
SQL0119N An expression starting with "SERVICEID" specified in a SELECT clause,HAVING clause, or ORDER BY clause is not specified in the GROUP BY clause or it is in a SELECT clause, HAVING clause, or ORDER BY clause with a column function and no GROUP BY clause is specified. SQLSTATE=42803
i got the same kind of error!!
|
|

03-31-04, 11:34
|
|
Registered User
|
|
Join Date: Mar 2004
Location: Toronto, ON, Canada
Posts: 513
|
|
Quote:
Originally posted by manth
i did this way as u said
db2 => SELECT LOG.SERVICEID, SVC.SERVICE_NAME, COUNT(*) FROM DB2A.CFGHDRLOG LOG, DB2A.CFGSERVICE SVC WHERE LOG.CHANNELID=3482 AND LOG.SERVICEID = SVC.SERVICEID GROUP BY SVC.SERVICE_NAME
SQL0119N An expression starting with "SERVICEID" specified in a SELECT clause,HAVING clause, or ORDER BY clause is not specified in the GROUP BY clause or it is in a SELECT clause, HAVING clause, or ORDER BY clause with a column function and no GROUP BY clause is specified. SQLSTATE=42803
i got the same kind of error!!
|
He said "add", you replaced... use both in the GROUP BY.
__________________
--
Jonathan Petruk
DB2 Database Consultant
|
|

03-31-04, 11:34
|
|
Registered User
|
|
Join Date: Feb 2004
Posts: 9
|
|
Try this
SELECT SVC.SERVICE_NAME, LOG.SERVICEID,COUNT(*) FROM DB2A.CFGHDRLOG LOG, DB2A.CFGSERVICE SVC WHERE LOG.CHANNELID=3482 AND LOG.SERVICEID = SVC.SERVICEID GROUP BY SVC.SERVICE_NAME, LOG.SERVICEID
Cheers
|
|

03-31-04, 13:29
|
|
Registered User
|
|
Join Date: Mar 2004
Posts: 54
|
|
It's working fine.
Thank you very much!
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|