gpt4 book ai didi

mysql - 为字段指定限定表名的替代解决方案

转载 作者:行者123 更新时间:2023-11-29 08:44:41 25 4
gpt4 key购买 nike

关于MySQL中的字段列表中的列''不明确错误。这是因为mysql无法判断字段名属于哪个表。除了将表名作为字段本身的前缀之外,有谁知道为字段指定限定表名的不同方法。假设我有一个像这样的字段列表

INSERT INTO dupes 
( lead_id,set_id,upload_date,agent,callcenter
,generation_date,vendors,first_name
,last_name,email,phone,address,city,state,zip,dob
,gender,marital_status,rented,year,make,model,trim
,vin,primary_use,miles_oneway,mileage,license_num,license_state
,education,job_title,license_status)

(SELECT lead_id,set_id,upload_date,agent,vendors,callcenter
,generation_date,first_name,last_name
,email,phone,address,city,state,zip,dob,gender,marital_status
,rented,year,make,model,trim,vin,primary_use,miles_oneway
,mileage,license_num,license_state,education,job_title
,license_status
FROM leads_auto
JOIN (
SELECT vendors, email, MIN(lead_id) min_lead_id
FROM leads_auto
WHERE vendors = 1762
GROUP BY vendors, email) y
ON y.vendors = leads_auto.vendors
AND y.email = leads_auto.email
AND leads_auto.lead_id <> y.min_lead_id)

现在我正在考虑使用 GROUP_CONCAT([fields] SEPARATOR ',[table name].') 将字段添加到变量中,然后执行它。还有其他人有什么想法吗?

最佳答案

我立即可以看到字段“电子邮件”不明确,因为它存在于您的第一个表 Leads_auto 中,并且您在 JOIN 中选择它。当您使用 JOIN 时,您应该为所有 SELECTions 添加显式表别名前缀,如下所示:

SELECT la.lead_id,la.set_id,la.upload_date,...  
FROM leads_auto la
JOIN (SELECT ...) y
...

这样您就可以引用 la.field_namey.field_name 并明确您的意思。

关于mysql - 为字段指定限定表名的替代解决方案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12806231/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com