English 中文(简体)
Bigquery table join with specific conditions
原标题:

I have this table A which contains

| ID   | Start Date | End Date |
|:---- |:----------:| --------:|
| 1    | 2020-03-01 |2020-03-02|
|      |  2020-05-01|2020-05-02|
| 2    |  2020-06-01|2020-06-02|

And table B contains

| ID   | Date     | sales |
|:---- |:--------:| -----:|
| 1    |2019-03-01| 10    |
| 1    |2021-03-02| 10    |
| 1    |2020-03-01| 10    |
| 1    |2020-03-02| 10    |
| 1    |2020-05-01| 10    |
| 1    |2020-05-02| 10    |
| 2    |2019-03-01| 10    |
| 2    |2021-03-02| 10    |
| 2    |2020-06-01| 10    |
| 2    |2020-03-02| 10    |
| 2    |2020-05-01| 10    |
| 2    |2020-06-02| 10    |
| 3    |2019-03-01| 10    |
| 3    |2021-03-02| 10    |
| 3    |2020-05-01| 10    |
| 3    |2020-05-02| 10    |

I want to exclude the results in Table B from Table A, if the ID in Table A is null then I will have to exclude the dates from all the results/IDs in Table B. So the final table will be

| ID   | Date     | sales |
|:---- |:--------:| -----:|
| 1    |2019-03-01| 10    |
| 1    |2021-03-02| 10    |
| 2    |2019-03-01| 10    |
| 2    |2021-03-02| 10    |
| 2    |2020-03-02| 10    |
| 3    |2019-03-01| 10    |
| 3    |2021-03-02| 10    |

I really appreciate any help you can provide.

问题回答

暂无回答




相关问题
trrying to optimize the query

I am just trying to left join and attach all the table but remaining table seems to be same is there any other way to attach the table like function or temp table to optimize it. SELECT Business ...

Slow query - Multiple joins and a lot of data

I m sure there is a better way I could be doing this. I have three main tables with large amounts of data to run through: records_main, sales, and appointments. Each with close to 20,000 records. I ...

Is an outer join possible with Linq to Entity Framework

There are many examples of outer join using Linq to Sql, all of them hinging on DefaultIfEmpty() which is not supported with Linq to Entity Framework. Does this mean that outer join is not possible ...

MYSQL DATE function running insanely slow in LEFT JOIN

When adding the line: LEFT JOIN core_records_sales as sales ON DATE(appointments.date) = DATE(sales.date_sold) To my query, it boosts the time for the script to run from about 8 seconds, to 2-3 ...

Limiting Access by Permission

thanks for viewing this. I have a db that has users, roles & user_roles. What I am trying to achieve is a login that will select users who have Admin or Associate permissions. The login then uses ...

热门标签