我试图使用sqldf编写嵌套查询。数据集是'contact_fb'。我试图只采取没有clubmahindra和列'from_name'中的不同名称的行,然后与'contact_fb'左连接以获取其他列中的所有信息。这是不给我想要的结果。如何使用sqldf创建嵌套查询
contact_fb =structure(list(X = 1:6, from_name = c("Club Mahindra", "Club Mahindra","pinto", "valencia", "valencia", "Club Mahindra"), type = structure(c(2L, 2L, 2L, 1L, 1L, 2L), .Label = c("link","photo", "status", "video"), class = "factor")), .Names = c("X","from_name", "type"), row.names = c(NA, 6L), class = "data.frame")
我在此尝试
names_cm=sqldf("select t1.from_name, t2.* from (select distinct from_name from contact_fb where from_name!='Club Mahindra') as t1 left join (select * from contact_fb) as t2 on t1.from_name=t2.t1.from_name")
我能得到它,最后通过
sqldf("select distinct(t1.from_name),t2.* from df t1 left join df t2 on (t1.from_name=t2.from_name) where t1.from_name!='Club Mahindra' group by t1.from_name")
我不明白的地方我去错了。我仍然可以通过我的方式得到它吗?
输出
3 Pinto photo
4 valencia link
仔细看看你的查询,你没有从表中选择任何东西。 – fhlgood
请用语言解释您正在尝试做什么并显示预期输出。 –
@谢谢MIKE芳我可以得到它的工作,但它仍然没有给出reqd结果。 –