0

I am trying to achieve the following result:

enter image description here

and I am doing so with the following statement

select
  invoice_N,
  buyer,
  max(count_order)
from (
    select
      invoice_N,
      buyer,
      count(distinct OrderIdent) as count_order
    from invoices
    left join orders on ...
    group by invoice_N, buyer 
)a
group by invoice_N, buyer

which is not correct. how can I select only the buyer with most orders for each invoice?

thank you in advance and best regards

Charlieface
  • 52,284
  • 6
  • 19
  • 43
CCC
  • 3
  • 2

0 Answers0