I have a table called "RegisteredProducts" with following columns:
ID_Reg
Name
ProductType
PackageType
I have another table called "Packages" with following columns:
ID_Pack
PackName
Weight
The last table is called "Products" with following columns:
ID_Product
ProdName
How do I write a query that will select all entries from "Registered Products", group them by ProductType and PackageType, and also sum the total weight of the selected products? In table "Packages", there is a column "Weight" that differs between package types.
Links between tables:
ProductType -> ID_Product
PackageType -> ID_Pack
Example:
Entries in table "RegisteredProducts":
ID_Reg Name ProductType PackageType
1 Sony 1 2
2 Asus 2 2
3 Asus 1 1
4 Albie 3 1
Entries in table "Packages":
ID_Pack PackName Weight(kg)
1 Internatio 20
2 Domesta 15
Entries in table "Products":
ID_Product ProdName
1 TV
2 Stereo
3 Lamp
So, the select statement shall be like this:
Product Weight shipped (kg)
TV
- Internatio 20
- Domesta 15
- Subtotal 35
Stereo
- Domesta 15
- Subtotal 15
Lamp
- Internatio 20
- Subtotal 20
TOTAL 70
So basically, just sum the total weight for each product and package type, with subtotals and totals of possible.
(Updated the post with an example)