我正在使用访问权限来运行查询,但这是说不支持联接操作。我已经检查了语法,看起来还不错。谁能帮我理解为什么失败了吗?
library(dplyr)
data_frame <- data_frame %>%
mutate(
weights = ifelse(group==1,probs1/probs1,
ifelse(group==2,probs1/probs2,
ifelse(group==3,probs1/probs3,
ifelse(group==4,probs1/probs4,NA))))
)
print(data_frame)
对于上下文,这是我的表
数据表
SELECT
d.uid,
md_20180901.monthval,
md_20180801.monthval,
md_20180701.val
FROM
(
(data as d
LEFT JOIN
(
SELECT
md.*
FROM
monthdata md
WHERE
md.monthval = #01/09/2018#
)
as md_20180901
ON d.UID = md_20180901.dataUID
AND md_20180901.monthval = #01/09/2018# )
LEFT JOIN
(
SELECT
md.*
FROM
monthdata md
WHERE
md.monthval = #01/08/2018#
)
as md_20180801
ON d.UID = md_20180801.dataUID
AND md_20180801.monthval = #01/08/2018#
)
LEFT JOIN
(
SELECT
md.*
FROM
monthdata md
WHERE
md.monthval = #01/07/2018#
)
as md_20180701
ON d.UID = md_20180701.dataUID
AND md_20180701.monthval = #01/07/2018#
WHERE
d.UID = "5B51141D";
月数据表
ID
UID
MYNAME
答案 0 :(得分:2)
仅在表达式中包含括号时,Access才支持联接表达式中的文字:
SELECT
d.uid,
md_20180901.monthval,
md_20180801.monthval,
md_20180701.val
FROM
(
(data as d
LEFT JOIN
(
SELECT
md.*
FROM
monthdata md
WHERE
md.monthval = #01/09/2018#
)
as md_20180901
ON (d.UID = md_20180901.dataUID
AND md_20180901.monthval = #01/09/2018#) )
LEFT JOIN
(
SELECT
md.*
FROM
monthdata md
WHERE
md.monthval = #01/08/2018#
)
as md_20180801
ON (d.UID = md_20180801.dataUID
AND md_20180801.monthval = #01/08/2018#)
)
LEFT JOIN
(
SELECT
md.*
FROM
monthdata md
WHERE
md.monthval = #01/07/2018#
)
as md_20180701
ON (d.UID = md_20180701.dataUID
AND md_20180701.monthval = #01/07/2018#)
WHERE
d.UID = "5B51141D";
但是,您在这里做的事情很奇怪。您还在比较内部子查询。删除那些:
SELECT
d.uid,
md_20180901.monthval,
md_20180801.monthval,
md_20180701.val
FROM
(
(data as d
LEFT JOIN
monthdata as md_20180901
ON (d.UID = md_20180901.dataUID
AND md_20180901.monthval = #01/09/2018#) )
LEFT JOIN
monthdata as md_20180801
ON (d.UID = md_20180801.dataUID
AND md_20180801.monthval = #01/08/2018#)
)
LEFT JOIN
monthdata as md_20180701
ON (d.UID = md_20180701.dataUID
AND md_20180701.monthval = #01/07/2018#)
WHERE
d.UID = "5B51141D";
答案 1 :(得分:0)
首先删除所有不必要的部分,然后将其简化。示例:
SELECT
md.*
FROM
monthdata md
WHERE
md.monthval = #01/09/2018#
)
as md_20180901
ON d.UID = md_20180901.dataUID
AND md_20180901.monthval = #01/09/2018#
可以简化:
(SELECT val FROM monthdata WHERE monthval=#01/09/2018#) md_20180901
ON d.UID=md_20180901.dataUID
除非字段名称冲突,否则无需重复表名称。
您不需要分配永远不会使用的别名(实际上,我通常只在两次使用同一张表的情况下才分配别名)。
您不需要在monthval
上添加ON
进行过滤,因为您已经在WHERE
中进行了过滤。
您实际收集的唯一字段是val
(monthval
实际上是一个固定值,因为您要按特定日期进行过滤),因此请不要使用*
。
清理查询并尝试一次添加一个monthval
,然后看看会发生什么情况。