我有一个查询:
select
a.kli,
b.term_desc,
count(distinct(a.adic)) as count,
a.partner_id
from
ad_delivery.sgmt_kli_adic a
join wand.wandterms b on a.kli = b.term_code
join wand.wandterms c on b.term_desc=c.term_desc
join dwh.sgmt_clients e on a.partner_id::varchar = e.partner_id
join dwh.schema_names f on e.partner_id::integer = f.partner_id::integer
where
a.partner_id::integer in (f.partner_id)
and c.class_code = 969
group by a.partner_id, b.term_desc, a.kli
order by partner_id, count desc;
这会带回每个 partner_id 的某些条款的计数。我希望能够按计数 desc 的顺序显示每个 ~40 partner_id 的前 10
查询结果看起来像
db=# SELECT * FROM xxx; pid | term_desc | count ----+------------+------ 4 | termdesc1 | 3434 4 | termdesc2 | 235 4 | termdesc3 | 367 4 | termdesc4 | 4533 5 | termdesc1 | 235 5 | termdesc2 | 567 5 | termdesc3 | 344 5 | termdesc4 | 56 (10k+ rows)