Understanding Date Aggregation by sql

Asked 2 years ago, Updated 2 years ago, 68 views

I use postgresql.

in SQL using two tables: A (date, month, quantity), B (start date, end date) "select sum (quantity) as total group by month" is the formula
I would like to exclude the quantity between the start and end dates, but
What should I do?
Thank you for your cooperation.

sql postgresql

2022-09-30 20:14

1 Answers

I solved myself.The following SQL works well.

 select month, sum (quantity) as total from A where not exists (select * from B where a. date between b. start date and b. end date) group by month


2022-09-30 20:14

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.