I am trying to find a way to SUM data in one column of my datbase on a SELECT statement if the Date column has the same day. My table would have three columns: Ticker, Mentions and Data. Ticker for this example would be BTC, there might be 10 rows and those ten rows have different mention counts(INT) for each one. Then the Date: 4 might have 2021-02-24, 5 might have 2021-02-25 and 1 might have 2021-02-23.
What I would like my SELECT statement to do is check that if the DAY is the same that it SUMs Mentions for that day and returns it as one INT. So in this case 3 INTs would be returned. A sum of the 24th, a sum of the 25th and then the single mention count of the 23.
Currently my SELECT looks like this:
SELECT Mentions
FROM crypto_currency_trend_data
WHERE Ticker = '" + ticker + "' AND YEAR(Date) = '" + current_year + "'
ORDER BY Date DESC
I have read about SUM(IF()) but I am not really sure how to apply it in this situation. Any advice is greatly appreciated.
SUM(Mentions)andGROUP BY Date?SUM(IF({all conditions}, column_to_sum, 0)). But I'd recommend CASE instead of IF - it looks more clear:SUM( CASE WHEN {all conditions} THEN column_to_sum ELSE 0 END)). And according GROUP BY, of course.