我如何从一个表中的组Id's分配给另一个表中的行,基于日期时间在开始和结束日期时间之间?[英] How do I assign group Id's from one table to rows in another based on datetimes being between start and finish datetimes?

本文是小编为大家收集整理的关于我如何从一个表中的组Id's分配给另一个表中的行,基于日期时间在开始和结束日期时间之间?的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

本文来自:IT宝库(https://www.itbaoku.cn)

我有两个表.表A有两个列,一个DateTime,一个数字.表B有几列,但是此问题的三个基本列:每行的唯一ID,一个开始日期和结束日期.表A对于表B的每一行都有多行,因此我想根据表B的表B中是否发生了DateTime的表B和表B的End DateTime之间的表B.假设表B中没有行具有重叠的启动间隔.

想象一下,基本上有许多实验是在开始和结束时间进行的,但是在没有实验ID的情况下,分别记录了实验的测量值,并且仅与数据进行了参考,在此期间进行了观测.

>

.

如何将表B ID分配给表A?

中的观察值

请,非常感谢您.

推荐答案

我会尝试这样的尝试:

select a.*, b.id
from a, b
where a.dt between b.start_dt and b.end_dt;

本文地址:https://www.itbaoku.cn/post/1968955.html

问题描述

I have two tables. Table A has two columns, one datetime, one numeric. Table B has several columns, but three essential columns to this problem: a unique Id for each row, a start datetime and an end datetime. Table A has multiple rows for each single row of Table B, so I want to assign the row Id's from Table B to the corresponding rows of Table A based on whether the Table A datetime occurs BETWEEN the start datetime and end datetime of Table B. Assume no rows in Table B have overlapping start-end intervals.

Imagine essentially many experiments were done with start and end times, but the measurements for the experiment were recorded separately without the experiment id's and only with datetimes to reference during which experiment the observations were made.

HOW DO I GET THE TABLE B ID'S ASSIGNED TO THE OBSERVATIONS IN TABLE A?

Please and most definitely thank you.

推荐答案

I would try someting like that:

select a.*, b.id
from a, b
where a.dt between b.start_dt and b.end_dt;