I have two queries which are doing basically the same thing, but have different grouping, the first query (query 1) is used to populate a chart, and the second to populate a table.
SELECT key_id ,sum(salary) ,sum(bonus) ,created_at FROM table WHERE emp_id = 1 GROUP BY key_id, created_at
SELECT key_id ,sum(salary) ,sum(bonus) ,count(*) OVER() AS full_count FROM table WHERE emp_id = 1 GROUP BY key_id
I have created a function that returns those two queries in a json format,
chart: [...], table: [...]. The problem is that I need to query the same table twice, because of my grouping. Is there any way of dealing with this situations?