I am trying to combine two query results into an output that looks like:
datetime | BC | AC
----------------------
sun | 1.0 | 0.9
through a sql call located below (in MySQL). I can make the individual statements query properly but the combined join does not work. Any suggestions? Thanks! Sorry about the formatting.
SELECT z.datetime, (z.w_1 + z.w_2 + z.w_3) as 'BC', (b.w_1 + b.w_2 + b.w_3) as 'AC'
(FROM monitor_data a
WHERE mon_id = "site A"
AND datetime > "2015-04-02 04:30:00"
AND datetime < "2015-04-02 06:30:00") z
JOIN (SELECT b.datetime, b.w_1, b.w_2, b.w_3
FROM monitor_data b
WHERE mon_id = "site B"
AND datetime> "2015-04-02 04:30:00"
AND datetime < "2015-04-02 06:30:00") y
ON y.datetime = z.datetime
You haven't got the syntax quite right. To join two derived tables (z and y), you'll need to ensure that each derived table has a syntactically complete SELECT statement. Also, remember that the second derived table is now aliased as 'y', not b:
SELECT z.datetime, (z.w_1 + z.w_2 + z.w_3) as BC,
(y.w_1 + y.w_2 + y.w_3) as AC
FROM
(
SELECT a.datetime, a.w_1, a.w_2, a.w_3
FROM monitor_data a
WHERE mon_id = 'site A'
AND datetime > '2015-04-02 04:30:00' AND datetime < '2015-04-02 06:30:00'
) z
JOIN
(
SELECT b.datetime, b.w_1, b.w_2, b.w_3
FROM monitor_data b
WHERE mon_id = 'site B'
AND datetime > '2015-04-02 04:30:00' AND datetime < '2015-04-02 06:30:00'
) y
ON y.datetime = z.datetime;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With