Last active
June 9, 2019 00:38
-
-
Save sofakingworld/29bb8c514a0e1a7dc5aa7c7386bfaa75 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
| ;WITH hours as ( | |
| ... | |
| ), | |
| incomes as ( | |
| SELECT * | |
| FROM sensor_triggers | |
| WHERE ... | |
| GROUP BY hour(created_at) | |
| ), | |
| outcomes as ( | |
| SELECT * | |
| FROM sensor_triggers | |
| WHERE ... | |
| GROUP BY hour(created_at) | |
| ), | |
| rows as ( | |
| SELECT * | |
| FROM hours | |
| LEFT JOIN incomes on incomes.hour = hours.hour | |
| LEFT JOIN outcomes on outcomes.hour = hours.hour | |
| ), | |
| final_row as ( | |
| SELECT | |
| 'Итог' literal | |
| sum(rows.incomes), | |
| sum(rows.outcomes) | |
| FROM rows | |
| ) | |
| SELECT * FROM rows | |
| UNION | |
| select * FROM final_row |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment