sqlite 将表A.Id与表B.Id匹配,然后返回表B.Country

wmtdaxz3  于 2022-12-27  发布在  SQLite
关注(0)|答案(1)|浏览(143)

我的SQLite数据库中有两个表,如下所示
表A:

| Id |   Date  | Rate | Person
    |:-- |:-------:| ----:| ------:|
    | 1  | 2022-02 | 6.3  | Alex   |
    | 1  | 2022-05 | 4.2  | John   |
    | 2  | 2022-09 | 2.5  | Alex   |
    | 3  | 2022-01 | 7.8  | David  |
    | 2  | 2022-21 | 9    | William|

表B:

| Id |    City   | Country |
    |:-- |:---------:| -------:|
    | 1  | London    | England |
    | 2  | Paris     | France  |
    | 3  | Washington| USA     |
    | 4  | Berlin    | Germany |

我需要一个查询,以获得ID和利率的每一行,在表A中,然后获得国家的ID在表B中的结果应该是这样的表C:

| Ids | Countries | Rates |
    |:--- |:---------:| -----:|
    | 1   |  England  |  6.3  |
    | 1   |  England  |  4.2  |
    | 2   |  France   |  2.5  |
    | 3   |  USA      |  7.8  |
    | 2   |  France   |   9   |
jljoyd4f

jljoyd4f1#

您需要将ABId连接起来,并选择一些列:

select B.Id as Ids, 
    B.Country as Countries, 
    A.Rate as Rates
From A inner join B on(A.Id = B.Id)

相关问题