I have two tables, one is products
and another is prices
like below
Products table
id name price
1 Computer 4
2 Printer 5
Prices table
id product_id date_start date_end price
1 1 2017-01-01 2017-01-31 2
2 1 2017-02-03 2017-02-23 3
Query: Get total price between 30.01.2017 and 05.02.2017? Expected Output:
30.01.2017 to 31.01.2017 2 days 2*2=4
01.02.2017 to 02.02.2017 2 days 2*4=8 /* this date is not defined in `prices` table, here we should take original price */
03.02.2017 to 05.02.2017 3 days 3*3=9
What could be the SQL that will give me 21?
I tried so much but no luck :(
Thanks in advance.