3

I have a table like this -

cdr_pkey as serial, calldate as timestamp, src as text, duration as bigint

I need to find top 10 most frequent numbers in 'src' column, together with the number of occurrence in the table by using SQL query.

I tried by exporting to Excel and run Mode function but the records are around 7 million so it is not so efficient.

PS. I'm using PostreSQL 9.1

2
  • Does that help? wiki.postgresql.org/wiki/Aggregate_Mode Commented Dec 10, 2012 at 10:20
  • @chl Thanks but not really. I prefer to have a step by step explanation so I can learn. Commented Dec 10, 2012 at 10:24

1 Answer 1

2
select 
    src as text,
    count(*) as total
from t
group by 1
order by total desc
limit 10;
Sign up to request clarification or add additional context in comments.

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.