0
How to create a function
SELECT
ii.sku,
ii.cod_setor,
ia.setor_ini,
ia.setor_fim,
sum(ii.quantidade) as quantidades,
ia.desc_ambiente,
ii.cod_coletor
FROM
item_inventarios ii
inner join inventario_ambientes ia on ii.id_inventario = ia.id_inventario
and ii.cod_setor between setor_ini and setor_fim
WHERE
ii.id_inventario = '46'
Group by ii.sku
order by 1
between right in the codeigniter is to be used within the Where, so you were facing problems
– Otto
Perfect, that way it works. However, this process is very slow .. I’m doing something wrong.?
– Hugo Rutemberg
Check that the filters are correct and clear ... the table indexes
– Otto
Filters and indexes are ok and yet mdemora records (11269 total, The consultation took 31.9350 seconds.)



SQL:


SELECT ii.cod_setor, ii.sku, sum(ii.quantidade) as quantidades, ia.desc_ambiente, ii.cod_coletor FROM item_inventarios ii inner join inventario_ambientes ia on ii.id_inventario = ia.id_inventario and ii.cod_setor between ia.setor_ini and ia.setor_fim WHERE ii.id_inventario = '117' Group by ii.cod_setor, ii.sku, ia.desc_ambiente, ii.cod_coletor order by 1
– Hugo Rutemberg
performs an explain in the direct query in the database that you discover pq this slow
– Otto
I received this reply:
id
select_type
table
type
possible_keys
key
key_len
ref
rows
Extra
1
SIMPLE
ia
ALL
NULL
NULL
NULL
NULL
14528
Using temporary; Using filesort
1
SIMPLE
ii
ALL
NULL
NULL
NULL
NULL
246291
Using where; Using join buffer (flat, BNL join)
– Hugo Rutemberg
Chief, come on it’s case for another post, so make it easy, we’re mixing a lack of knowledge of Codeigniter with poorly formed or slow sql problem
– Otto
All right. Obg.
– Hugo Rutemberg