Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong solution for Question 6 in step4.md #22

Open
vibhabellutagi19 opened this issue Jul 23, 2022 · 1 comment
Open

Wrong solution for Question 6 in step4.md #22

vibhabellutagi19 opened this issue Jul 23, 2022 · 1 comment

Comments

@vibhabellutagi19
Copy link

vibhabellutagi19 commented Jul 23, 2022

The solution for Question 6 in step4.md is wrong.

Question - Summarise all buy and sell transactions for each member_id by generating 1 row for each member with the following additional columns:

  • Bitcoin buy quantity
  • Bitcoin sell quantity
  • Ethereum buy quantity
  • Ethereum sell quantity

Given Solution -

SELECT
  member_id,
  SUM(
    CASE
      WHEN ticker = 'BTC' AND txn_type = 'BUY' THEN quantity
      ELSE 0
    END
  ) AS btc_buy_qty,
  SUM(
    CASE
      WHEN ticker = 'BTC' AND txn_type = 'SELL' THEN quantity
      ELSE 0
    END
  ) AS btc_sell_qty,
  SUM(
    CASE
      WHEN ticker = 'ETH' AND txn_type = 'BUY' THEN quantity
      ELSE 0
    END
  ) AS eth_buy_qty,
  SUM(
    CASE
      WHEN ticker = 'BTC' AND txn_type = 'SELL' THEN quantity
      ELSE 0
    END
  ) AS eth_sell_qty
FROM trading.transactions
GROUP BY member_id;

Issue - In the last case, the ticker is filtered with BTC, it should be ETH.

Correct solution -

SELECT
  member_id,
  SUM(
    CASE
      WHEN ticker = 'BTC' AND txn_type = 'BUY' THEN quantity
      ELSE 0
    END
  ) AS btc_buy_qty,
  SUM(
    CASE
      WHEN ticker = 'BTC' AND txn_type = 'SELL' THEN quantity
      ELSE 0
    END
  ) AS btc_sell_qty,
  SUM(
    CASE
      WHEN ticker = 'ETH' AND txn_type = 'BUY' THEN quantity
      ELSE 0
    END
  ) AS eth_buy_qty,
  SUM(
    CASE
      WHEN ticker = 'ETH' AND txn_type = 'SELL' THEN quantity
      ELSE 0
    END
  ) AS eth_sell_qty
FROM trading.transactions
GROUP BY member_id;
@fortunewalla
Copy link

The solution for Question 5 in step4.md is wrong.

could you do a pull request to correct this in the main repo?

@vibhabellutagi19 vibhabellutagi19 changed the title Wrong solution for Question 5 in step4.md Wrong solution for Question 6 in step4.md Feb 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants