Firebird 如何计算表中的所有记录并将最大到最小排序

use*_*478 0 sql firebird2.5

我的数据库结构

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
Run Code Online (Sandbox Code Playgroud)

如何在 firebird 中获得结果并对其进行排序。

Table 1
customer     |    Frequency
cust_c               4
cust_a               3
cust_e               3
cust_d               2
cust_b               1
Run Code Online (Sandbox Code Playgroud)

注意..现在我使用这个命令,它非常慢。真实数据为9800条记录

select first 10 skip 0 distinct
    customer, (select count(*) from table_1 pdr
    where pdr.customer = prd.customer)
from
    table_1 prd
Run Code Online (Sandbox Code Playgroud)

Bri*_*lia 5

select customer, count(*) as freq
from table_1
group by customer
order by 2 desc, 1
limit 10
Run Code Online (Sandbox Code Playgroud)