Using generate_series in ecto and passing a value
Using generate_series in ecto and passing a value I am trying to use generate_series in this query to get the number of sales in a time period even with the days that have no sales. I got it working with a hard-coded value but now I need to get all the sales since the contract was created. What I have so far: query = from( c in Contract, join: v in Voucher, on: v.contract_id == c.id, join: s in Sale, on: s.voucher_id == v.id and c.id == ^contract_id, right_join: day in fragment( "select generate_series(current_date - interval '60 day', current_date, '1 day')::date AS d" ), on: day.d == fragment("date(?)", s.date), group_by: day.d, select: %{ number_sales: count(s.id), total_value: sum(s.value), date: day.d }, order_by: [asc: day.d] ) Repo.all(query) |> Enum.map(fn entry -> Map.put(entry, :date, Date.from_erl!(entry.date)) end) With this query I get all the s...