0

I have tables like following I'd like to count duplicate and assign them.

customer date       type
A       2020/8/1     a
A       2020/8/1     b
B       2019/5/1     a
B       2019/6/1     c

I'd like to count duplicate in customeranddate the, assign the number of duplicate of them.

["customer,"date"]

customer date     type     duplicate
A       2020/8/1   a       2
A       2020/8/1   b       2
B       2019/5/1   a       1
B       2019/6/1   c       1

If someone has opinion to assign the number of duplicated rows. Please let me know. thanks

2 Answers 2

1

With count() over analytical function.Date is reserved word

SELECT c.*,
       COUNT(*) OVER (PARTITION BY "customer","date") duplicate 
FROM   tablename c;

If you wanted to format date column

SELECT "customer",
        to_char("date",'DD-MON-YYYY HH:MI:SS AM') "date",
        "type",
       COUNT(*) OVER (PARTITION BY "customer","date") duplicate 
FROM tablename ;
Sign up to request clarification or add additional context in comments.

Comments

0

You can try the below -

select a.customer,a.date,type,duplicate 
from tablename a
join 
(select customer,date, count(*) as duplicate from tablename group by customer, date) b 
on a.customer=b.customer and a.date=b.date

Comments

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.