I am trying to write an sql query that outputs data for a python script. The python script will eventually push that data to a table so to make things smoother, I decided to cast the output as char.
The data that I have is organized by 15min periods. Data A and data B are stored on one table and have columns start_time (as a datetime), counts A, and counts B. The second table has start_time (as a datetime), and counts C.
What I need is sum for A, B, and C for each day. However, I want to sum conditionally where it only counts in the sum where the other two data counts are not NULL for that 15 min period. For example, if a "row" for a 15 min period has data for A and B but not C, it would not count in the sum. How do I implement this conditional?
example output:
date| SUM(A) | SUM(B) | SUM(C)
I can write without the conditional like this (new to sql):
SELECT
DATE('timezone conversion') AS date,
cast(SUM(p1.COUNT_DATA_A) as char)
AS A,
cast(SUM(p1.COUNT_DATA_B) as char)
AS B,
cast(SUM(p2.COUNT_DATA_C) as char)
AS C
FROM
table_data_A_B
AS p1
LEFT JOIN table_data_C
AS p2 ON p1.start_time = p2.start_time
WHERE
DATE('timezone conversion') >= '2018-03-27'
AND DATE('timezone conversion') < '2018-03-29'
GROUP BY DATE('timezone conversion')
ORDER BY DATE(p1.start_time) DESC
How would I implement the conditional in this query? I appreciate the help. I am a bit new to stackoverflow, coding and sql in general but I will try my best to be helpful.