DataBrewery / cubes

[NOT MAINTAINED] Light-weight Python OLAP framework for multi-dimensional data analysis
http://cubes.databrewery.org
Other
1.49k stars 312 forks source link

Subquery to facts table #443

Open stdword opened 7 years ago

stdword commented 7 years ago

Hello, guys!

I need to have all items from dimension table with or without joined facts from facts table. So I need to construct a subquery to facts table with RangeCut or any other cut. It is important to filter fact table before joining.

I need to execute the following SQL query:

SELECT T.id, coalesce(sum(T.value), 0)
FROM dim_table
  LEFT OUTER JOIN (
     SELECT * FROM fact_table WHERE EXTRACT(YEAR FROM fact_table.date) >= 2017
  ) as T ON T.dim_id = dim_table.id
WHERE  ...
GROUP BY ...
ORDER BY ...

How to do that with cubes framework?