1

Topic: Grouping and pivot

I should write advanced query with a bias to statistics. It is necessary to group in attributes and values. Thus attribute Counter is not grouped. Its value is added for group. If attribute Counter one in group that it comes across is deleted. The initial data on  in application. Column Property_ID has two values 22 and 33. 22 it is attribute quantity which to us it is necessary to add.
Here a label:
attribute value count Property_ID INSTANCE_ID
quantity 2 3 22 9722
BagID bag 3 33 9722
ItemID item 3 33 9722
quantity 2 3 22 9723
BagID bag 3 33 9723
ItemID item 3 33 9723
quantity 5 2 22 9724
BagID bag 2 33 9724
quantity 10 2 22 9725
ItemID item 2 33 9725
BagID bag 1 33 9727
Here SQL which forms the table:
Problem in grouping and addition. BagID - bag are grouped with ItemID - item, quantity are added = 4
It is group INSTANCE_ID 9722 + 9723.
From INSTANCE_ID 9724 it is received only BagID - bag with quantity = 5 .
For the last case with INSTANCE_ID 9727 quantity = 1 with it there are no problems by means of check across the field count.
What SQL is necessary before transformation PIVOT in which will attribute (columns), value, quantity
In application  the table:

2

Re: Grouping and pivot

ErikI;
I if am fair  did not understand from your description.
You on what columns should have a grouping?
[quote =] It is group INSTANCE_ID 9722 + 9723.

Here it explain why group 9722 + 9723 instead of for example 9722 + 9725?