简体   繁体   English

MySQL基于不同值的左连接匹配

[英]MySQL left join match based on distinct values

I'm looking to join two tables based on dates.我希望根据日期连接两个表。 The date value in one of the tables can occur multiple times but I need a match based on a unique instance of the date.其中一个表中的日期值可以多次出现,但我需要基于日期的唯一实例进行匹配。 Here is what I have that does not work:这是我所拥有的不起作用的东西:

select idt.Incident_DateCopy, wt.weather_main
 from incidentdatatwo as idt left join weather as wt on 
     (select distinct(Incident_DateCopy) from incidentdata) as idate = wt.dt_iso

... ...

try this尝试这个

if not work so please send you table schema如果不起作用,请向您发送表架构

SELECT idt.Incident_DateCopy, wt.weather_main , 
(SELECT DISTINCT(Incident_DateCopy) FROM incidentdata) AS idate 
 FROM incidentdatatwo AS idt LEFT JOIN weather AS wt ON
HAVING idate = wt.dt_iso

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM