There is a certain amount, you need to calculate using the procedure, what quantity of goods you can buy for it. The quantity of goods in stock is limited, it must also be taken into account.

SELECT quantity, price FROM Goods WHERE ID=1; 

1) Produce select and get the quantity and price of the goods with the desired ID. How to proceed further with the data? Can I use quantity, price as variables and continue to perform operations with them in the same way as in programming languages?

2) For tests, I created a construction of checking the case when the amount allows you to buy the entire product, so that in this case the quantity of the product would simply be displayed. But the design does not work. What is the mistake?

 CREATE PROCEDURE test begin IF((SELECT quantity * price FROM Goods WHERE ID=1;) < 1000) THEN SELECT quantity FROM Goods WHERE ID=1; END IF; end 

1 answer 1

MySQL syntax:

 select Name, price, @ByNow := IF(@MyCount/Price>cnt,cnt,TRUNCATE(@MyCount/price,0)) as Покупаем, cnt - @ByNow as Товаров_в_магазине_осталось, @MyCount:=@MyCount-Price*@ByNow as Остаток_денег from NAMES_01, (select @MyCount:=5000) c, (select @ByNow:=0) d order by price; 

https://rextester.com/ZIZXLX48732