【发布时间】:2021-11-25 18:05:13
【问题描述】:
我有这张桌子:
id band_id musician_id date_join date_left band_name active_years_begin active_years_end
1 2 7 1960-01-01 1970-12-31 The Beatles 1960-01-01 1970-12-31
2 2 8 1960-01-01 1970-12-31 The Beatles 1960-01-01 1970-12-31
3 2 9 1960-01-01 1970-12-31 The Beatles 1960-01-01 1970-12-31
4 2 10 1960-01-01 1970-12-31 The Beatles 1960-01-01 1970-12-31
5 3 9 1971-12-31 1981-01-01 Wings 1971-12-31 1981-01-01
6 6 5 2017-08-01 NULL Band1 2017-08-01 NULL
7 7 6 2019-09-01 NULL Band2 2019-09-01 NULL
8 4 5 2018-09-01 NULL Band3 2018-09-01 NULL
9 5 5 2018-09-01 NULL Band4 2018-09-01 NULL
10 9 5 2021-09-01 NULL Band5 2018-09-01 NULL
我只需要为所有乐队参与者选择参与者设置的乐队名称(date_join == active_years_begin and (date_left is null or active_years_end is null) or (date_left == active_years_end)))。
所以这里的正确答案是披头士乐队、Wings、Band1、Band2、Band3、Band4。
我该怎么做?
【问题讨论】:
-
为什么不用 Band5? Band5 没有成员变动。
-
@jarlh,它有。它于 2018 年 9 月 1 日开始存在,并于 2021 年 9 月 1 日新成员加入该乐队。所以这个乐队空了 3 年,然后换了。
-
到目前为止,您是否尝试过任何查询?如果是,请提出问题以便更好地理解
-
我明白了。我认为你应该有一张乐队桌和一张音乐桌。