Busiest stock per client

ranking

Busiest stock per client

Zerodha SQL Interview Question

Zerodha earns on volume, so the account team wants each client's biggest stock by the money moved through it. Both directions count: a client who bought ten lakh and sold ten lakh generated twice the business of one who only bought.

For each client, return the client_id, the symbol they moved the most money through, and that amount as traded_value.

Asked of

  • Data Analyst
  • Business Analyst
  • BI Analyst
  • Product Analyst
  • Analytics Engineer
  • Data Engineer
  • Data Scientist

zerodha_tradesTable21 rows

Column NameType
trade_idBIGINT
client_idVARCHAR
symbolVARCHAR
traded_onDATE
sideVARCHAR
quantityBIGINT
priceDOUBLE

zerodha_tradesExample Input

trade_idclient_idsymboltraded_onsidequantityprice
9001Z1001INFY2024-07-01buy1001450
9002Z1001TCS2024-07-02buy403800
9003Z1001INFY2024-07-03buy501480
9004Z1001INFY2024-07-05sell801520
9005Z1001TCS2024-07-06sell153950
9006Z1001INFY2024-07-08sell701495
9007Z1001TCS2024-07-09buy253870
9020Z1004INFY2024-07-02buy1501440
9021Z1004INFY2024-07-10sell1501530

Example Output

client_idsymboltraded_value
Z1001INFY445250
Z1004INFY445500

Explanation

Z1001 moved 445250 through INFY and 308000 through TCS, so INFY is their busiest stock. Z1004 traded only INFY, buying and then selling the same 150 shares, and both sides of that count toward the total.

The example above is a small slice of the data. Your query runs against the full tables.