I have three tables with tbl_goods ,tbl_units and tbl_sat which looks like this :
tbl_goods, consists of sold goods
+--------+-------+-------+-------+
| goods |code |qty |unit |
+--------+-------+-------+-------+
| cigar | G001 | 1 | pack |
| cigar | G001 | 2 | pcs |
| cigar | G001 | 2 | box |
| bread | G002 | 2 | pcs |
| bread | G002 | 2 | pack |
| soap | G003 | 1 | pcs |
+--------+-------+-------+-------+
and tbl_units as below :
+--------+-------------+-------+
| code |ucode |qty |
+--------+-------------+-------+
| KG001 | U001 | 10 |
| KG001 | U002 | 20 |
| KG002 | U001 | 15 |
+--------+-------------+-------+
I add letter 'K' in front of code in tbl_units to differ and make sure not collide with code in tbl_goods.
and tbl_sat as below :
+--------+-------------+
| ucode | unit |
+--------+-------------+
| U001 | pack |
+--------+-------------+
| U002 | box |
+--------+-------------+
| U003 | crate | etc
so only cigar and bread will have conversion because table units have the code
what the result I need to show as below :
+--------+-------+-------+-------+--------+
| goods |code |qty |unit | total |
+--------+-------+-------+-------+--------+
| cigar | G001 | 1 | pack | 10 |
| cigar | G001 | 2 | pcs | 2 |
| cigar | G001 | 2 | box | 40 |
| bread | G002 | 2 | pcs | 2 |
| bread | G002 | 2 | pack | 30 |
| soap | G003 | 1 | pcs | 1 |
+--------+-------+-------+-------+--------+
Actually this question already been asked and might similar but the changes in table structure and coding, so I think I start another new question. Hopefully this can solve my problem
Thank you very much
Regards