Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Elixir 将左外部联接查询转换为EXTO_Elixir_Phoenix Framework_Ecto - Fatal编程技术网

Elixir 将左外部联接查询转换为EXTO

Elixir 将左外部联接查询转换为EXTO,elixir,phoenix-framework,ecto,Elixir,Phoenix Framework,Ecto,我不知道如何将SQL语句翻译成EXTO 凤凰城设置 SQL语句 选择days.date\u值,periods.name FROM days 左侧外部联接插槽打开(days.id=slots.day\u id) 左外连接周期打开(slots.period\u id=periods.id和 (periods.country_id=1或 期间(联邦(州(id=5)) 其中days.date_值>='2017-01-01'和 days.date\u值Aleft\u连接默认情况下执行left-OUTER连

我不知道如何将SQL语句翻译成EXTO

凤凰城设置 SQL语句
选择days.date\u值,periods.name FROM days
左侧外部联接插槽打开(days.id=slots.day\u id)
左外连接周期打开(slots.period\u id=periods.id和
(periods.country_id=1或
期间(联邦(州(id=5))
其中days.date_值>='2017-01-01'和

days.date\u值A
left\u连接
默认情况下执行
left-OUTER连接
。如果对表使用相同的别名,则查询的其余部分很容易转换。如果将
start\u on
ends\u on
定义为具有适当值的
Date
结构,则此操作应适用于:

query = from(
             days in Day,
             left_join: slots in MehrSchulferien.Calendar.Slot,
             on: days.id == slots.day_id,
             left_join: periods in MehrSchulferien.Calendar.Period,
             on: slots.period_id == periods.id and
                 (periods.country_id == ^federal_state.country_id or
                  periods.federal_state_id == ^federal_state.id),
             where: days.date_value >= ^starts_on and
                    days.date_value <= ^ends_on,
             order_by: days.date_value
            )
query=from(
日复一日,
left_join:mehrschulferein.Calendar.Slot中的插槽,
on:days.id==slots.day\u id,
左联合:mehrschulferein.Calendar.Period中的句点,
on:slots.period_id==periods.id和
(periods.country\u id=^federal\u state.country\u id或
periods.federal_state_id=^federal_state.id),
其中:days.date_值>=^start_日期和

days.date\u值连接函数接受一个参数,该参数用于指定您需要的连接类型。除此之外,在我们为您完成所有工作之前,最好先看看您尝试了什么。我已经完成了,但无法使用Ecto。@wintermeyer您对该答案的最新编辑更改了逻辑AFAICS。我认为您应该编辑您r问题,因为现在的答案将生成与问题不同的查询,可能会让未来的读者感到困惑。完成。这样做更有意义。
SELECT days.date_value, periods.name FROM days 
LEFT OUTER JOIN slots ON (days.id = slots.day_id) 
LEFT OUTER JOIN periods ON (slots.period_id = periods.id and 
(periods.country_id = 1 OR 
periods.federal_state_id = 5)) 
WHERE days.date_value >= '2017-01-01' AND 
days.date_value <='2017-12-31' 
ORDER BY days.date_value;
query = from(
             days in Day,
             left_join: slots in MehrSchulferien.Calendar.Slot,
             on: days.id == slots.day_id,
             left_join: periods in MehrSchulferien.Calendar.Period,
             on: slots.period_id == periods.id and
                 (periods.country_id == ^federal_state.country_id or
                  periods.federal_state_id == ^federal_state.id),
             where: days.date_value >= ^starts_on and
                    days.date_value <= ^ends_on,
             order_by: days.date_value
            )