I have a query effectively using 2 tables, Model and Model Parts.
Model contains the model number and other attributes such as serial number.
Model parts contain all the parts used to repair the model.
There are many models with the same number; the serial number makes it unique. For each model there can be many parts.
For each model I want to take a count of each different model part used.
This is quite easy using group by and count. However I want to go one stage further. At he moment I can produce something like this
Model Part Count
11111a 11234 22
11111a 14321 9
11111a 15523 3
11111a 13232 8
11111b 11234 5
11111b 14321 12
11111b 95523 2
11111b 93232 2
What I want to be able to differentiate is for a specific part whether or not another specific part was used on the repair. For example let's say I'm interested in part 14321 and 11234. For part 14321 I want 2 counts depending on whether it was used on the same repair as 11234. So I get something like (and this is made up)
Model Part Count
11111a 11234 22
11111a 14321 2 (used twice on the same repair as 11234)
11111a 14321 7 (7 times not on same repair)
11111a 15523 3
11111a 13232 8
11111b 11234 5
11111b 14321 1 (used once on the same repair as 11234)
11111b 14321 11 (7 times not on same repair)
11111b 95523 2
11111b 93232 2
Hope this is clear!!
Model contains the model number and other attributes such as serial number.
Model parts contain all the parts used to repair the model.
There are many models with the same number; the serial number makes it unique. For each model there can be many parts.
For each model I want to take a count of each different model part used.
This is quite easy using group by and count. However I want to go one stage further. At he moment I can produce something like this
Model Part Count
11111a 11234 22
11111a 14321 9
11111a 15523 3
11111a 13232 8
11111b 11234 5
11111b 14321 12
11111b 95523 2
11111b 93232 2
What I want to be able to differentiate is for a specific part whether or not another specific part was used on the repair. For example let's say I'm interested in part 14321 and 11234. For part 14321 I want 2 counts depending on whether it was used on the same repair as 11234. So I get something like (and this is made up)
Model Part Count
11111a 11234 22
11111a 14321 2 (used twice on the same repair as 11234)
11111a 14321 7 (7 times not on same repair)
11111a 15523 3
11111a 13232 8
11111b 11234 5
11111b 14321 1 (used once on the same repair as 11234)
11111b 14321 11 (7 times not on same repair)
11111b 95523 2
11111b 93232 2
Hope this is clear!!