内部连接而没有唯一标识符

发布于 2025-02-01 08:43:49 字数 659 浏览 3 评论 0原文

在下面的屏幕截图上,您可以看到两个表。在左侧,我有一张带有事故的桌子,在这种情况下,ID是唯一的,并且ID = 68始终是同一事故。

右侧是特定日期温度可用的天气数据。

但是,由于我的案例在一月份存在五个星期六,因此日期并非唯一可识别。 我要做的是在我的第一个“事故”表(空列)中写下温度。

我知道这是一个问题,因为我不想在桌子上发生五次事故(ID = 68应该保持独特)。 即使温度不能100%正确,是否可以加入此数据?我对平均温度感到满意,或者只是使用第一个条目。

这是我的查询,它永远不会停止运行。

UPDATE accident_copy as a
LEFT JOIN wetterdaten as w
ON a.year = w.year
    and a.monthDE = w.month
    and a.day = w.day
    and a.hour = w.hour
SET a.Temperatur = w.Temperatur;
    

On the screenshot below you see two tables. On the left side I have a table with accidents, in this case the ID is unique and it is always the same accident with ID=68.

On the right side is the weather data available with the temperature of the specific day.

However, the date is not uniquely identifiable since there exists five Saturday's in January in my case.
What I am trying to do, is to write the temperature in my first "Accident" table (empty column).

I know that there is a problem since I don't want to have five times the same accident in my table (id=68 should remain uniquely).
Is there a way to join this data even if the temperature will not be 100% correct? I am happy with an average of the temperature, or just use the first entry.

This is my query, it never stops to run.

UPDATE accident_copy as a
LEFT JOIN wetterdaten as w
ON a.year = w.year
    and a.monthDE = w.month
    and a.day = w.day
    and a.hour = w.hour
SET a.Temperatur = w.Temperatur;
    

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

苦妄 2025-02-08 08:43:49

相反,使用子查询在当时获得平均温度:

UPDATE accident_copy as a
LEFT JOIN 
   (
      SELECT avg(temperatur) temparatur, year, month, day, hour 
      FROM wetterdaten
      GROUP BY year, month, day, hour
    ) as w
ON a.year = w.year
    and a.monthDE = w.month
    and a.day = w.day
    and a.hour = w.hour
SET a.Temperatur = w.Temperatur;

Instead use a subquery to get your average temperature for that time:

UPDATE accident_copy as a
LEFT JOIN 
   (
      SELECT avg(temperatur) temparatur, year, month, day, hour 
      FROM wetterdaten
      GROUP BY year, month, day, hour
    ) as w
ON a.year = w.year
    and a.monthDE = w.month
    and a.day = w.day
    and a.hour = w.hour
SET a.Temperatur = w.Temperatur;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文