Dear ErnieAlex, Thank you so much for taking your valuable time,
The first and second statements return my intended results, but I donβt understand why does not the third statement return a correct results? For example, the TOTAL_EXPORTATION_QUANTITY for slat must be 200, but it shows 400. Also, Final is not correct. (However in previous queries, those were OK.)
Here are my 3 tables.
CREATE TABLE
bom(
idint(11) NOT NULL,
material_codetext NOT NULL,
material_nametext NOT NULL,
product_sizetext NOT NULL,
unittext NOT NULL,
material_typetext NOT NULL,
base_quantitytext NOT NULL,
actual_quantitytext NOT NULL,
supplierstext NOT NULL,
product_codetext NOT NULL,
product_linetext NOT NULL,
company_nametext NOT NULL,
bom_nametext NOT NULL,
description` text NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
β
β Dumping data for table bom
INSERT INTO bom
(id
, material_code
, material_name
, product_size
, unit
, material_type
, base_quantity
, actual_quantity
, suppliers
, product_code
, product_line
, company_name
, bom_name
, description
) VALUES
(32, β1β, βsaltβ, β1500β, βgramβ, βconsumableβ, β50β, β75β, βzamandiβ, β251β, βserakβ, βcheshmeβ, βdefaultβ, ββ),(33, ββ, βmilkβ, β1500β, βgramβ, βconsumableβ, β700β, β1050β, ββ, β251β, βserakβ, βcheshmeβ, βdefaultβ, ββ),(34, ββ, βnanaβ, β1500β, βgramβ, βconsumableβ, β50β, β75β, ββ, β251β, βserakβ, βcheshmeβ, βdefaultβ, ββ),(36, ββ, βlabelβ, β1500β, βgramβ, βpackagingβ, β0.02β, β0.02β, ββ, β251β, βserakβ, βcheshmeβ, βdefaultβ, ββ),(37, ββ, βwaterβ, β1500β, βgramβ, βconsumableβ, β750β, β1125β, ββ, β252β, βserakβ, βcheshmeβ, βdefaultβ, ββ),(38, ββ, βmilkβ, β1500β, βgramβ, βconsumableβ, β650β, β975β, ββ, β252β, βserakβ, βcheshmeβ, βdefaultβ, ββ),(39, ββ, βhashtgiahβ, β1500β, βgramβ, βconsumableβ, β17.5β, β26.25β, ββ, β252β, βserakβ, βcheshmeβ, βdefaultβ, ββ), (40, ββ, βlabelβ, β1500β, βgramβ, βpackagingβ, β0.1β, β0.1β, ββ, β252β, βserakβ, βcheshmeβ, βdefaultβ, ββ), (41, ββ, βpreformβ, β1500β, βunitβ, βpackagingβ, β1β, β1β, ββ, β252β, βserakβ, βcheshmeβ, βdefaultβ, ββ), (42, ββ, βpreformβ, β1500β, βunitβ, βpackagingβ, β1β, β1β, ββ, β251β, βserakβ, βcheshmeβ, βdefaultβ, ββ),(45, ββ, βmilkβ, β1000β, βgramβ, βconsumableβ, β1000β, β1000β, ββ, β533β, βsidelβ, βbaharβ, β1β, ββ),(46, ββ, βpriform 1000β, β1000β, βunitβ, βpackagingβ, β1β, β1β, ββ, β533β, βsidelβ, βbaharβ, β1β, ββ),(47, ββ, βmilkβ, β1500β, βgramβ, βconsumableβ, β800β, β1200β, ββ, β251β, βserakβ, βcheshmeβ, β1β, ββ),
(48, ββ, βnanaβ, β1500β, βgramβ, βconsumableβ, β98β, β147β, ββ, β251β, βserakβ, βcheshmeβ, β1β, ββ); `
here is the second table
CREATE TABLE production_data
(
id
int(11) NOT NULL,
uid
int(11) NOT NULL,
user_recorder
text NOT NULL,
product_name
text NOT NULL,
product_size
text NOT NULL,
product_code
text NOT NULL,
product_line
text NOT NULL,
pdate
text NOT NULL,
shift
text NOT NULL,
start_time
time NOT NULL,
finish_time
time NOT NULL,
duration
text NOT NULL,
product_quantity
text NOT NULL,
unit
text NOT NULL,
reusable_waste
text NOT NULL,
unusable_waste
text NOT NULL,
bom_name
text NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
β
β Dumping data for table production_data
INSERT INTO production_data
(id
, uid
, user_recorder
, product_name
, product_size
, product_code
, product_line
, pdate
, shift
, start_time
, finish_time
, duration
, product_quantity
, unit
, reusable_waste
, unusable_waste
, bom_name
) VALUES
(2, 0, βmohamadβ, ββ, ββ, β123β, βcheshmeβ, β2020/3/22β, β2β, β18:00:00β, β22:00:00β, β04:00:00β, β31000β, ββ, β560β, β300β, ββ),
(3, 0, βmohamadβ, ββ, β1500β, β123β, βcheshmeβ, β2020/3/22β, β3β, β22:00:00β, β07:00:00β, β09:00:00β, β67000β, ββ, β0β, β0β, ββ),
(4, 0, βmohamadβ, ββ, ββ, β254β, βserakβ, β2020/3/22β, β3β, β22:30:00β, β00:30:00β, β02:00:00β, β5862β, ββ, β0β, β0β, ββ),
(5, 0, βmohamadβ, ββ, ββ, β252β, βserakβ, β2020/3/22β, β3β, β00:40:00β, β07:00:00β, β06:20:00β, β136138β, ββ, β0β, β0β, βdefaultβ),
(6, 0, βmohamadβ, ββ, β1500β, β254β, βserakβ, β2020/3/22β, β2β, β17:51:00β, β22:30:00β, β04:39:00β, β61000β, ββ, β0β, β0β, ββ),
(7, 0, βmohamadβ, ββ, ββ, β251β, βserakβ, β2020/3/22β, β1β, β07:00:00β, β12:45:00β, β05:45:00β, β45045β, ββ, β0β, β0β, β1β),
(8, 0, βmohamadβ, ββ, ββ, β251β, βserakβ, β2020/3/21β, β2β, β20:19:00β, β22:30:00β, β02:11:00β, β8000β, ββ, β0β, β0β, βdefaultβ),
(9, 0, βmohamadβ, ββ, ββ, β251β, βserakβ, β2020/3/21β, β3β, β22:30:00β, β07:00:00β, β08:30:00β, β108000β, ββ, β0β, β0β, βdefaultβ);
here is the third table:
CREATE TABLE stock_information
(
id
int(11) NOT NULL,
material_code
text NOT NULL,
material_name
text NOT NULL,
unit
text NOT NULL,
material_group
text NOT NULL,
importation_date
text NOT NULL,
expiration_date
text NOT NULL,
importation_quantity
text NOT NULL,
suppliers_id
text NOT NULL,
suppliers_name
text NOT NULL,
exportation_date
text NOT NULL,
exportation_quantity
text NOT NULL,
exportation_customer_id
text NOT NULL,
exportation_customer_name
text NOT NULL,
exportation_receiver
text NOT NULL,
company
text NOT NULL,
description
text NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
β
β Dumping data for table stock_information
INSERT INTO stock_information
(id
, material_code
, material_name
, unit
, material_group
, importation_date
, expiration_date
, importation_quantity
, suppliers_id
, suppliers_name
, exportation_date
, exportation_quantity
, exportation_customer_id
, exportation_customer_name
, exportation_receiver
, company
, description
) VALUES
(1, β2β, βsugarβ, ββ, ββ, β2019/3/21β, β2019/3/24β, β200β, β17β, ββ, ββ, ββ, ββ, ββ, ββ, ββ, ββ),
(2, β2β, βsugarβ, ββ, β ', β2020/3/31β, β2020/11/10β, β3000β, β15β, ββ, ββ, ββ, ββ, ββ, ββ, ββ, ββ),
(3, β1β, βmilkβ, ββ, β ', β2020/7/26β, β2020/7/29β, β125β, β20β, ββ, ββ, ββ, ββ, ββ, ββ, ββ, ββ),
(4, β2β, βsugarβ, ββ, β ', β2020/6/28β, β2021/2/10β, β2500β, β15β, ββ, ββ, ββ, ββ, ββ, ββ, ββ, ββ),
(5, β3β, βnanaβ, ββ, β ', β2020/5/5β, β2020/10/12β, β200β, β21β, ββ, ββ, ββ, ββ, ββ, ββ, ββ, ββ),
(6, β1β, βmilkβ, ββ, β ', β2020/8/30β, β2020/9/2β, β150β, β18β, ββ, ββ, ββ, ββ, ββ, ββ, ββ, ββ),
(7, β1β, βmilkβ, ββ, β ', ββ, ββ, ββ, ββ, ββ, β2020/5/5β, β100β, β4β, ββ, ββ, ββ, ββ),
(8, β1β, βmilkβ, ββ, β ', ββ, ββ, ββ, ββ, ββ, β2020/8/3β, β150β, β4β, ββ, ββ, ββ, ββ),
(9, β1β, βmilkβ, ββ, β ', ββ, ββ, ββ, ββ, ββ, β2020/6/9β, β250β, β4β, ββ, ββ, ββ, ββ),
(10, β2β, βsugarβ, ββ, β ', ββ, ββ, ββ, ββ, ββ, β2020/8/2β, β1500β, β4β, ββ, ββ, ββ, ββ),
(11, β3β, βnanaβ, ββ, β ', ββ, ββ, ββ, ββ, ββ, β2020/7/27β, β150β, β7β, ββ, ββ, ββ, ββ),
(12, β2β, βsugarβ, ββ, β ', ββ, ββ, ββ, ββ, ββ, β2020/5/11β, β300β, β4β, ββ, ββ, ββ, ββ),
(13, β1β, βmilkβ, ββ, β ', ββ, ββ, ββ, ββ, ββ, β2020/10/12β, β200β, β4β, ββ, ββ, ββ, ββ),
(14, β3β, βnanaβ, ββ, β ', β2020/7/6β, β2020/8/23β, β250β, β21β, ββ, ββ, ββ, ββ, ββ, ββ, ββ, ββ),
(15, β2β, βsugarβ, ββ, β ', ββ, ββ, ββ, ββ, ββ, β2020/7/28β, β1000β, β4β, ββ, ββ, ββ, ββ),
(16, β2β, βsugarβ, ββ, β ', ββ, ββ, ββ, ββ, ββ, β2020/7/25β, β200β, β4β, ββ, ββ, ββ, ββ),
(17, β2β, βsugarβ, ββ, β ', ββ, ββ, ββ, ββ, ββ, β2020/7/26β, β200β, β1β, ββ, ββ, ββ, ββ),
(18, β3β, βnanaβ, ββ, β ', ββ, ββ, ββ, ββ, ββ, β2020/7/26β, β500β, β3β, ββ, ββ, ββ, ββ),
(19, β1β, βmilkβ, ββ, β ', β2020/3/21β, β2020/3/24β, β250β, β17β, ββ, ββ, ββ, ββ, ββ, ββ, ββ, ββ),
(20, β1β, βmilkβ, ββ, β ', β2020/3/20β, β2020/3/24β, β500β, β17β, ββ, ββ, ββ, ββ, ββ, ββ, ββ, ββ),
(21, β1β, βmilkβ, ββ, β ', ββ, ββ, ββ, ββ, ββ, β2020/3/21β, β70β, β4β, ββ, ββ, ββ, ββ),
(22, β1β, βmilkβ, ββ, β ', ββ, ββ, ββ, ββ, ββ, β2020/3/22β, β100β, β4β, ββ, ββ, ββ, ββ),
(23, β5β, βsaltβ, ββ, β ', ββ, ββ, ββ, ββ, ββ, β2020/3/21β, β200β, β4β, ββ, ββ, ββ, ββ),
(24, β4β, βhashtgiahβ, ββ, β ', ββ, ββ, ββ, ββ, ββ, β2020/3/21β, β100β, β4β, ββ, ββ, ββ, ββ),
(25, β4β, βhashtgiahβ, ββ, β ', ββ, ββ, ββ, ββ, ββ, β2020/3/22β, β160β, β4β, ββ, ββ, ββ, ββ);
I was wondering if you could help me with this
Best Regards