user3793478
user3793478

Reputation: 47

Firebird howto count all record in table and sort max to min

My DB Structure

Table_1
Customer    |
cust_a
cust_a
cust_a
cust_c
cust_c
cust_c
cust_c
cust_b
cust_d
cust_d
cust_e
cust_e
cust_e

How to get result and sort it like this in firebird.

Table 1
customer     |    Frequency
cust_c               4
cust_a               3
cust_e               3
cust_d               2
cust_b               1

Note .. now i use this command it's very slow. and real data is 9800 records

select first 10 skip 0 distinct
    customer, (select count(*) from table_1 pdr
    where pdr.customer = prd.customer)
from
    table_1 prd

Upvotes: 0

Views: 1851

Answers (1)

Brian DeMilia
Brian DeMilia

Reputation: 13248

select customer, count(*) as freq
from table_1
group by customer
order by 2 desc, 1
limit 10

Upvotes: 5

Related Questions