我的数据库结构
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
如何在firebird中获得结果并将其排序。
Table 1
customer | Frequency
cust_c 4
cust_a 3
cust_e 3
cust_d 2
cust_b 1
注意..现在我使用这个命令它很慢。和实际数据是9800条记录
select first 10 skip 0 distinct
customer, (select count(*) from table_1 pdr
where pdr.customer = prd.customer)
from
table_1 prd
答案 0 :(得分:2)
select customer, count(*) as freq
from table_1
group by customer
order by 2 desc, 1
limit 10