troubleshooting Question

Force sql rows

Avatar of johnnyg123
johnnyg123Flag for United States of America asked on
Microsoft SQL ServerSQL
8 Comments1 Solution38 ViewsLast Modified:
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
ASKER CERTIFIED SOLUTION
Sharath S
Data Engineer

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 8 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros