1

Topic: Help please with request creation?

Kind time of days. Help please with request creation? It would be necessary to arrange a cycle on basis what to select.
There is a table depo_outgo these are the proceeding goods from a warehouse. When we request the report on current month it is necessary to eliminate repetition of show of following positions.
If the identical:
- The goods name
- The purchase price
- The sale price
That the filter we search for such goods and it is summable also an amount.
The Amount the goods can be in a month to go on different in it to us important to consider the identical goods adding their amount sent in a month.
For example
Yesterday :
The refrigerator an amount = 2 , the Price =100, the Price =150
Today :
The refrigerator an amount = 3 , the Price =100, the Price =150
Tomorrow :
The refrigerator an amount = 4 , the Price =100, the Price =150
As you see we send the identical goods with identical margins in a month but with different amounts.
In the report on a month we should sees only so :
The refrigerator an amount = 6 , the Price =100, the Price =150
That I do:
1) I Search unique for the name of the goods.  by name so. Because in depo_outgo are stored only ID the goods id_tov

SELECT ` id_tov `, (SELECT ` name ` FROM ` depo_income ` WHERE ` depo_income `. ` id ` = ` depo_outgo `. ` id_tov `) AS name
FROM ` depo_outgo`
WHERE
` company_id ` = ' 67'
AND ` deleted ` = 0
AND FROM_UNIXTIME (` insert_date `, ' %Y%m ') = ' 201611 ' GROUP BY ` id_tov`
ORDER BY name'

2) Further On a cycle on each goods I search identical DISTINCT the purchase Price the sale Price

SELECT DISTINCT depo_price, price
FROM ` depo_outgo`
WHERE
` id_tov ` = ' 258'
AND ` company_id ` = ' 67'
AND ` deleted ` = 0
AND FROM_UNIXTIME (` insert_date `, ' %Y%m ') = ' 201611'

3) Further On a cycle I search if in the table depo_outgo there are a little identical goods with the purchase Price the sale Price that add only their amount sum (` quantity `) AS quantity

SELECT sum (` quantity `) AS quantity
FROM ` depo_outgo`
WHERE ` depo_price ` = ' 25.30 ' AND ` price ` = ' 31.80'
AND ` id_tov ` = ' 258'
AND ` company_id ` = ' 67'
AND ` deleted ` = 0
AND FROM_UNIXTIME (` insert_date `, ' %Y%m ') = ' 201611'

Thus it turns out to eliminate repetitions
How it is possible to optimize these actions? In requests it is not strong help please?

2

Re: Help please with request creation?

Syrbek wrote:

For example
Yesterday :
The refrigerator an amount = 2 , the Price =100, the Price =150
Today :
The refrigerator an amount = 3 , the Price =100, the Price =150
Tomorrow :
The refrigerator an amount = 4 , the Price =100, the Price =150
As you see we send the identical goods with identical margins in a month but with different amounts.
In the report on a month we should sees only so :
the Refrigerator an amount = 6 , the Price =100, the Price =150

Here be there 5, 7 or 9 - I would understand... But 6 at me well it does not turn out in any way...

3

Re: Help please with request creation?

Akina wrote:

it is passed...
Here be there 5, 7 or 9 - I would understand... But 6 at me well it does not turn out in any way...

I ask a pardon for a misprint there should be a total [color=red] the Refrigerator an amount = 9 an error in my description

4

Re: Help please with request creation?

Well then it is simple GROUP BY + SUM (). All turns out one request.

5

Re: Help please with request creation?

Akina wrote:

Well then it is simple GROUP BY + SUM (). All turns out one request.

Briefly it is not clear. It is possible on more in detail?