tsql sum data and include default values for missing data
- by markpirvine
Hi,
I would like a query that will shouw a sum of columns with a default value for missing data. For example assume I have a table as follows:
type_lookup:
id name
1 self
2 manager
3 peer
And a table as follows
data:
id type_lookup_id value
1 1 1
2 1 4
3 2 9
4 2 1
5 2 9
6 1 5
7 2 6
8 1 2
9 1 1
After running a query I would like a result set as follows:
type_lookup_id value
1 13
2 25
3 0
I would like all rows in type_lookup table to be included in the result set - even if they don't appear in the data table.
Any help would be greatly appreciated,
Mark