0
I’m having difficulties to assemble this query in Codeigniter, someone can give a little help?
select
venda_itens.secao, venda_itens.secao_nome,
sum(venda_itens.qtd_itens_finalizada) as qtd_itens,
sum(venda_itens.qtd_itens_cancelada) as qtd_itens_cancelados,
sum(case when venda_itens.preco_desconto_cancelada is not null then
venda_itens.preco_desconto_cancelada else venda_itens.preco_total_cancelada end) as valor_canceladas,
sum(case when venda_itens.preco_desconto_finalizada is not null
then venda_itens.preco_desconto_finalizada else venda_itens.preco_total_finalizada end) as valor_total
from vendas as v
join (
select
v.id as venda_id,
v.status,
vi.secao, vi.secao_nome,
sum(case when v.status = "finalizada" then vi.quantidade end) as qtd_itens_finalizada,
sum(case when v.status = "cancelada" then vi.quantidade end) as qtd_itens_cancelada,
sum(case when v.status = "finalizada" then vi.preco_desconto end) as preco_desconto_finalizada,
sum(case when v.status = "finalizada" then vi.preco_total end) as preco_total_finalizada,
sum(case when v.status = "cancelada" then vi.preco_desconto end) as preco_desconto_cancelada,
sum(case when v.status = "cancelada" then vi.preco_total end) as preco_total_cancelada
from vendas as v
join vendas_itens as vi on vi.vendas_id = v.id
where (v.data_venda between '2018-04-02 00:00:00' and '2018-04-02 23:59:59')
and (vi.secao between 1 and 30)
group by vi.secao
) as venda_itens on venda_itens.venda_id = v.id
where (v.data_venda between '2018-04-02 00:00:00' and '2018-04-02 23:59:59')
and (venda_itens.secao between 1 and 30)
group by venda_itens.secao
order by v.data_venda desc, venda_itens.secao;
please specify further your question....
– aa_sp
That one query can function without need of construction see Regular Queries. You’ll only use the Query Builder Class if it is really very convenient. And the point here is this: Why it would be more convenient to use the constructor in your query?
– ShutUpMagda
Ball show! You can say, if with this method has how to leave the dynamic date?
– Cyro Dubeux