1

I have a table such as the following

**SP     MA     SL   NG**
jame     j001   1    20200715
jame     j001   -1   20200715
jame     j001   1    20200715
pink     p002   12   20200720 
pink     p002   -3   20200720 
pink     p002   12   20200721 

I'm trying to count record but I have to eliminate duplicates. So, I want a result like

 **SP    count
jame     1
pink     2

Any suggestions?I could do with some help, please. Thanks you!

1

1 Answer 1

2

Are you looking for count(distinct ...)?

For example, if you want the count of distinct values in column ng for each sp:

select sp, count(distinct ng) cnt from mytable group by sp

If you want to eliminate records that are complete duplicates, another option is select distinct in a subquery first:

select sp, count(*) cnt
from (select distinct sp, ma, sl, ng from mytable) t
group by sp
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks you for your help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.