sql >> Base de Datos >  >> Database Tools >> phpMyAdmin

Ifs anidados en un select-where para un filtrado dinámico condicional

¿Está buscando un join y group by ?

select f.id,
       count(*) as num_rows,
       sum(tare) as sum_tare
from history h join
     temp_fetch f
     on h.nom like concat('%', f.client, '%') or
        h.commune like concat('%', f.commune, '%')  or 
        h.type like concat('%', f.type, '%') or 
        h.mat like concat('%', f.matricule, '%') or 
        h.tare like concat('%', f.tare, '%')
where f.cancled = 0
group by f.id;