Created
October 15, 2013 07:24
-
-
Save fengdragon/6987810 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT deviceTable.ID, ed.measure_time, ed.value | |
FROM ( | |
SELECT (CASE WHEN d2.id IS NULL THEN d1.id ELSE d2.id END) AS ID | |
FROM device d1 | |
LEFT JOIN device d2 ON d2.owner=d1.id | |
WHERE d1.parent=11 AND d1.owner IS NULL AND d1.is_active=1 AND d1.is_excluded=0 ) AS deviceTable | |
JOIN electricity_data ed ON ed.device_id = deviceTable.ID | |
Where ed.measure_time BETWEEN '2013-05-18 00:00:00' AND '2013-05-20 23:59:59' | |
SELECT d.id, ed.measure_time, ed.value | |
FROM device d LEFT JOIN electricity_data ed ON ed.device_id = d.id | |
WHERE d.is_active=1 | |
AND ( d.owner is null or d.owner != 69 ) | |
AND d.is_excluded=0 | |
AND ed.device_id = d.id | |
AND d.parent = 11 | |
AND ed.measure_time BETWEEN '2013-05-18 00:00:00' AND '2013-05-18 00:01:59' | |
ORDER BY d.is_parent desc, ed.device_id, ed.measure_time; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment