I have 3 SQL SERVER data tables :
TBL_HOUSE :
|"ID_HOUSE"|"ID_PERSONS"|"QTY_PERSONS"|
|"1" |"|1|2|3|" |"|1|2|1|" |
|"2" |"|2|" |"|3|" |
TBL_PERSON :
|"ID_PERSON"|"ID_PETS"|"QTY_PETS"|
|"1" |"|3|1|" |"|1|2|" |
|"2" |"|1|2|" |"|3|1|" |
TBL_PET :
|"ID_PET"|"PET_TYPE"|"PET_PRICE"|
|"1" |"DOG" |"500" |
|"2" |"CAT" |"200" |
I have to make two queries.
The first for retrieve the number of each PET in a house.
ie. : In the HOUSE"2", there is 3 PERSON"2"
for each PERSON"2" there is 3 DOG and 1 CAT
In total in the HOUSE"2" is 9 DOG and 3 CAT.
The second to get the total value of pets in a house.
In HOUSE"2", the total value is 5100. (3*(3*500+1*200) = 5100)
Can you help me to write these queries?
Thanks a lot.