Answer the question
In order to leave comments, you need to log in
Is it possible to combine 2 requests into 1?
Is it possible to combine 2 requests into one?
$products= \R::getAll("SELECT * FROM product_status JOIN product ON product.status_id = product_status.id JOIN pay ON product.paysystem_id = pay.pay_id");
$query = " SELECT product.*,(SUM(pay.summa)/product.price)*100 AS 'percent' FROM product JOIN pay ON (product.paysystem_id=pay.pay_id) GROUP BY product.id ";
$pay = \R::getAll($query);
Answer the question
In order to leave comments, you need to log in
Without knowing exactly the structure of tables and unique indexes, it is definitely impossible to answer.
In general, I do not advise doing this, requests overloaded by logic almost always turn out to be slower than 2 separate requests.
In MS SQL, this option works fine:
SELECT product_status.*,
product.*,
pay.*,
((SELECT SUM(pay.summa)
FROM pay
WHERE pay.pay_id = product.paysystem_id)/product.price)*100 AS 'percent'
FROM product_status
JOIN product
ON product.status_id = product_status.id
JOIN pay
ON pay.pay_id = product.paysystem_id
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question