Avatar of johnnyg123
johnnyg123
Flag for United States of America

asked on 

Force sql rows

Here is some data from 2 sql 2014 tables

CustomerOrder

id      year              Amount
1      2017      200
1      2019      300
2      2010       500

OrderYear

Year
2016
2017
2018
2019
2020

Trying to write a query that will return how much customer order from 2016 to 2020

If customer didn't order anything in a given year, would like to have a row returned with 0 amount

Given the sample data

Would like the query results to be

ID  Year       Amount
1     2016     0
1     2017    200
1     2018     0
1     2019     300
1     2020     0
2     2016     0
2     2017     0
2     2018     0
2     2019     0
2     2020     0
Microsoft SQL ServerSQL

Avatar of undefined
Last Comment
slightwv (䄆 Netminder)

8/22/2022 - Mon