|
View previous topic :: View next topic
|
| Author |
Message |
Chidane
New User
Joined: 25 Nov 2021 Posts: 34 Location: India
|
|
|
|
Hi Team,
I have the requirement as follows. I have a DB2 table with following fields
| Code: |
FUNC NAME LOCATION
ABC JAMES 001
ABC JAMES 002
ABC JAMES 003
DEF JAMES 001
DEF JAMES 002
DEF TIM 001
ABC ROY 001
DEF ROY 002
XYZ ROY 001 |
Here I would like to know, for each FUNC, how many unique NAME are tagged. So I would like to have output as
| Code: |
FUNC COUNT
ABC 2
DEF 3
XYZ 1 |
Here Func ABC has 2 persons tagged (James and Roy) ; DEF has 3 persons tagged (James, Tim and Roy) ; XYZ has only ROY tagged.
I have tried putting the code as , however this is not giving correct results
SELECT FUNC, COUNT(NAME) FROM TABLE_A
GROUP BY FUNC
Can you please help me to acheive this result |
|
| Back to top |
|
 |
sergeyken
Senior Member

Joined: 29 Apr 2008 Posts: 2283 Location: USA
|
|
|
|
RTFM about SQL option: GROUP BY
P.S.
Please, do not post topics in this style:
| Quote: |
I'm given the task to do this and this. I have no idea, how to do it. Can you please do my job for me?
Thank you very much. |
|
|
| Back to top |
|
 |
Chidane
New User
Joined: 25 Nov 2021 Posts: 34 Location: India
|
|
|
|
Thanks.
I tried this and worked.
SELECT FUNC, COUNT(DISTINCT NAME) FROM TABLE_A
GROUP BY FUNC |
|
| Back to top |
|
 |
|
|