Я пытаюсь выполнить запрос MySQL, чтобы получить последнее количество продукции (которое было ранее добавлено пользователем, которое в этом сценарии равно 7) из таблицы, называемой производством, но я получаю самое высокое производство. Это таблицы:
_____ Production ___________
"production_id","prod_id","production_date","production_qty"
"1","40001","2020-04-15","35"
"2","40002","2019-02-08","54"
"3","40002","2020-04-08","67"
"4","40001","2020-04-02","76"
"5","40001","2020-05-08","21"
"6","40001","2020-04-29","34"
"7","40003","2020-04-03","545"
"8","40003","2020-04-18","7"
"9","40001","2020-04-25","6"
"10","40001","2020-04-25","6"
"11","40001","2020-04-25","6"
"12","40002","2020-04-13","5"
"13","40003","2020-04-01","5"
"14","40001","2020-04-17","3"
"15","40003","2020-04-04","2"
"16","40002","2020-04-11","45"
"17","40001","2020-04-02","4"
"18","40002","2020-04-01","3"
"19","40003","2020-04-17","2"
"20","40003","2020-04-29","3"
______ Products ____________
"product_id","product_name","product_unit","product_group","product_size"
"40001","tested","Gram","EVA","7/10"
"40002","testing","KG","EVA","7/10"
"40003","teste454","KG","PU","7/10"
Это мой запрос:
SELECT product_id, product_unit, production_qty, SUM(production_qty) as prod_in_hand FROM
products JOIN production ON products.product_id = production.prod_id WHERE product_id =
40003 AND production_date < CURRENT_DATE
Приведенный выше запрос создает такой результат:
prod_id, product_unit, production_qty, prod_in_hand
40003, KG, 545, 561
Но я ожидаю "7 "как production_qty. Как я могу это сделать? Я использую XAMPP Server phpMyAdmin MariaDB версия сервера 10.3.16