I am trying to get distinct column value and count in db2

sIGPAD_PORT
80
80
3334
3334
10
II am trying to get the following from the table above


80 2
3334 2
10 1



.
[COUNT[DISTINCT ]]SIGPAD_PADPORT] asSIGPAD_PAD, ProjectId
FROM TBLUSERSESSION
WHERE EmpId IN 
]
    EmpId
    FROM TBLUSERSESSION
    GROUP BY SIGPAD_PADPORT
    HAVING COUNT >=1 
    ]

Open in new window

LVL 6
r3nderAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

r3nderAuthor Commented:
[COUNT[DISTINCT ]]SIGPAD_PADPORT] asSIGPAD_PAD
FROM TBLUSERSESSION
WHERE EmpId IN 
]
    EmpId
    FROM TBLUSERSESSION
    GROUP BY SIGPAD_PADPORT
    HAVING COUNT >=1 > 1
    ]

Open in new window

0
hnasrCommented:
Compare with this sql, and use your specific syntax.

table a(f1)
f1
80
80
3334
3334
10

Query:
SELECT f1, count(f1) AS cnt
FROM a
GROUP BY f1

Open in new window

Result:
f1      cnt
10      1
80      2
3334      2
0
r3nderAuthor Commented:
I gget an error
SELECT SIGPAD_PORT, COUNT(SIGPAD_PORT) AScntr
FROM TBLUSERSESSION GROUPBY SIGPAD_PORT

Open in new window

unexpected token SIGPAD_PORT was found following LUSERSESSION GROUPBY - I thought maybebe a mispelled column name or  incorrect case but both  are right
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

aikimarkCommented:
You might need to delimit the field name, since it contains an underscore.  Try this.
SELECT [SIGPAD_PORT], COUNT([SIGPAD_PORT]) AS cntr
FROM TBLUSERSESSION 
GROUP BY [SIGPAD_PORT]

Open in new window

0
Kent OlsenData Warehouse Architect / DBACommented:
Hi r3nder,

I think the DB2 tag on your question confuses the issue. tblUserSession isn't one of the default DB2 tables, but it is a SQL Server table.

The basic query that you ask for in the original post can be easily solved like this:

SELECT sigpad_padport, count(*)
FROM tblUserSession
GROUP BY sigpad_padport


Kent
0
hnasrCommented:
Modify Ascntr, GROUPBY
 in your statement:
SELECT SIGPAD_PORT, COUNT(SIGPAD_PORT) AScntr
FROM TBLUSERSESSION GROUPBY SIGPAD_PORT
to:
SELECT SIGPAD_PORT, COUNT(SIGPAD_PORT) As cntr
FROM TBLUSERSESSION GROUP BY SIGPAD_PORT
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Dave FordSoftware Developer / Database AdministratorCommented:
SELECT SIGPAD_PORT,
       COUNT(SIGPAD_PORT) AS cntr
  FROM TBLUSERSESSION
 GROUP BY SIGPAD_PORT
;

Open in new window

0
r3nderAuthor Commented:
I am unsure what you were saying ken but it was close to the solution - thank yoyu and to eveyone else as well
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
DB2

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.