i有一个eTrade交易表。我想
SELECT symbol, sum(shares), (price * shares) as cost, sum(total) as total
FROM transactions_orig
WHERE type = 'EQ' AND IF(transaction = 'dividend', shares <> 0, ??)
GROUP BY symbol
HAVING sum(shares) > 0
因此,我只想在交易类型为股息并且股票不等于0的情况下包括该行。这意味着股息已被重新投资而不是以现金支付。如果交易等于股息,而股份等于零。忽略该行。
我敢肯定我已经想到了这个..但是我无法弄清楚。以下是一些示例数据
1. Dividend EQ LGCY 0 114.00 0.00
2. Credit UNKNOWN 0 9.99 0.00
3. Bought EQ BBEP 100 -1978.99 19.69
4. Dividend EQ T 0 157.50 0.00
5. Dividend EQ T 4.42686 -157.50 0.00
6. Adjustment UNKNOWN 0 -90.00 0.00
我要排除的是排等行(如第4行(付款),但包括第5行(购买更多股份)
我了解您的要求。您需要选择所有交易,但排除零股份的股息。
格式从
的Where子句格式化WHERE type = 'EQ' AND IF(transaction = 'dividend', shares <> 0, ??)
to
WHERE type = 'EQ' AND ((transaction = 'dividend' and shares <> 0) OR transaction <> 'dividend')
类似的东西?
SELECT symbol, sum(shares), (price * shares) as cost, sum(total) as total
FROM transactions_orig
WHERE type = 'EQ' AND transaction = 'dividend' and shares <> 0
GROUP BY symbol
HAVING sum(shares) > 0