我有两个数据帧,我想使用dplyr加入.一个是包含名字的数据框.
test_data <- data.frame(first_name = c("john", "bill", "madison", "abby", "zzz"),
stringsAsFactors = FALSE)
Run Code Online (Sandbox Code Playgroud)
另一个数据框包含Kantrowitz名称语料库的清理版本,用于识别性别.这是一个最小的例子:
kantrowitz <- structure(list(name = c("john", "bill", "madison", "abby", "thomas"), gender = c("M", "either", "M", "either", "M")), .Names = c("name", "gender"), row.names = c(NA, 5L), class = c("tbl_df", "tbl", "data.frame"))
Run Code Online (Sandbox Code Playgroud)
我基本上想要test_data使用kantrowitz表格从表中查找名称的性别.因为我要将它抽象为一个函数encode_gender,所以我不知道将要使用的数据集中列的名称,因此我不能保证它将会被name用作,例如kantrowitz$name.
在基础RI中将以这种方式执行合并:
merge(test_data, kantrowitz, by.x = "first_names", by.y = "name", all.x = TRUE)
Run Code Online (Sandbox Code Playgroud)
返回正确的输出:
first_name gender
1 abby either
2 bill either
3 john M
4 madison …Run Code Online (Sandbox Code Playgroud) 如何更改此查询以便返回所有u.usergroups?
from u in usergroups
from p in u.UsergroupPrices
select new UsergroupPricesList
{
UsergroupID = u.UsergroupID,
UsergroupName = u.UsergroupName,
Price = p.Price
};
Run Code Online (Sandbox Code Playgroud) 我正在运行这个SQL查询:
SELECT wp_woocommerce_order_items.order_id As No_Commande
FROM wp_woocommerce_order_items
LEFT JOIN
(
SELECT meta_value As Prenom
FROM wp_postmeta
WHERE meta_key = '_shipping_first_name'
) AS a
ON wp_woocommerce_order_items.order_id = a.post_id
WHERE wp_woocommerce_order_items.order_id =2198
Run Code Online (Sandbox Code Playgroud)
我收到这个错误:
#1054 - 'on子句'中的未知列'a.post_id'.
我认为我的代码很简单,但我做不到.我究竟做错了什么?
我有这个代码
User.find(:all, :limit => 10, :joins => :user_points,
:select => "users.*, count(user_points.id)", :group =>
"user_points.user_id")
Run Code Online (Sandbox Code Playgroud)
它生成以下sql
SELECT users.*, count(user_points.id)
FROM `users`
INNER JOIN `user_points`
ON user_points.user_id = users.id
GROUP BY user_points.user_id
LIMIT 10
Run Code Online (Sandbox Code Playgroud)
是否可以以其他方式进行LEFT JOIN而不是INNER JOIN,User.find_by_sql并且可以手动输入查询?
我有2个数据帧:
restaurant_ids_dataframe
Data columns (total 13 columns):
business_id 4503 non-null values
categories 4503 non-null values
city 4503 non-null values
full_address 4503 non-null values
latitude 4503 non-null values
longitude 4503 non-null values
name 4503 non-null values
neighborhoods 4503 non-null values
open 4503 non-null values
review_count 4503 non-null values
stars 4503 non-null values
state 4503 non-null values
type 4503 non-null values
dtypes: bool(1), float64(3), int64(1), object(8)`
Run Code Online (Sandbox Code Playgroud)
和
restaurant_review_frame
Int64Index: 158430 entries, 0 to 229905
Data columns (total 8 columns):
business_id 158430 non-null …Run Code Online (Sandbox Code Playgroud) 我有这个跨数据库查询...
SELECT
`DM_Server`.`Jobs`.*,
`DM_Server`.servers.Description AS server,
digital_inventory.params,
products.products_id,
products.products_pdfupload,
customers.customers_firstname,
customers.customers_lastname
FROM `DM_Server`.`Jobs`
INNER JOIN `DM_Server`.servers ON servers.ServerID = Jobs.Jobs_ServerID
JOIN `cpod_live`.`digital_inventory` ON digital_inventory.jobname = Jobs.Jobs_Name
JOIN `cpod_live`.`products` ON products.products_pdfupload = CONCAT(digital_inventory.jobname, ".pdf")
JOIN `cpod_live`.`customers` ON customers.customers_id = products.cID
ORDER BY `DM_Server`.`Jobs`.Jobs_StartTime DESC LIMIT 50
Run Code Online (Sandbox Code Playgroud)
它运行良好,直到我做它们LEFT JOIN.我认为通过不指定一种类型的连接,它被认为是一种LEFT JOIN.这不是这种情况吗?
有什么区别Left Join and Left Outer Join?
如何从customers1和customers2获取所有产品包括他们的客户名称?
customer1 table
cid name1
1 john
2 joe
customer2 table
cid name2
p1 sandy
p2 linda
product table
pid cid pname
1 1 phone
2 2 pencil
3 p1 pen
4 p2 paper
Run Code Online (Sandbox Code Playgroud)
结果应该是这样的
pid cid pname name1 name2
1 1 phone john NULL
2 2 pencil joe NULL
3 p1 pen NULL sandy
4 p2 paper NULL linda
Run Code Online (Sandbox Code Playgroud) 是否可以在sql查询中使用多个左连接?
LEFT JOIN
ab
ON
ab.sht = cd.sht
Run Code Online (Sandbox Code Playgroud)
我想添加一个这样的附加查询吗?它会起作用吗?
LEFT JOIN
ab AND aa
ON
ab.sht = cd.sht
AND
aa.sht = cc.sht
Run Code Online (Sandbox Code Playgroud)
这会有用吗?
我有2个实体,A和B.它们是相关的,但我不想将关系映射添加到bean.
我们如何使用左外之间的连接A和B使用HQL或标准?
有一些可用的解决方法,
我总是回过头来看这2个选项,还有其他选择吗?或者这不可能?