Conditional Sum

Another question one of my students has sent me. This question tests your understanding of SQL Group Functions . Given the following betting activity table (bet_tbl table) :


שאלת SQL ראיון עבודה - טבלת הימורים

As you can see, each row represents one placed bet, and includes the following fields:

  • betID – bet number
  • CustomerID – customer number
  • betDate – the date in which this bet was made
  • betOutcome – the bet outcome, 0 represents a loss and 1 represents a win.
  • amount – the amount of money the customer has lost or won.

First task – Create a query to display the biggest loss, and the biggest win for each customer:


שאלת SQL ראיון עבודה - סכום רווח והפסד

Second Task – Create a query to display the overall amount of win / loss for each customer:


שאלת SQL ראיון עבודה - רווחהפסד מצטבר

UpScale Analytics is one of the largest platforms in the world for learning SQL by doing, consisting over 300 SQL exercises at different levels (including solutions), by topics, across over 100 different datasets. More…