Top n clients which account for half of the total sales

Get the sales data of 2010 from SALES table in a database, and pick out the big client in this year. The big client refers to the top n clients which account for half of the total sales.

Solution:

A
1
=demo.query("select * from SALES where year(ORDERDATE)=2010")
2
=A1.groups(CLIENT;sum(AMOUNT):Amount)
3
=A2.sort@z(Amount)
4
=A3.sum(Amount)/2
5
0
6
=A3.select((A5=A5+Amount,A5<=A4))
7
=A6.(CLIENT)

The computation in A7 is shown below: