SELECT
	i.id_item AS cod_item,
	i.descripcion AS item,
	i.unidad1 AS unidad_medida,
	i.peso AS peso_kg,
	IF(i.tipo = 1, 'Producto', 'Servicio') AS tipo,
	l.id_linea AS cod_linea,
	l.descripcion AS sublinea,
	la.id_linea_analisis AS cod_linea_analisis,
	la.descripcion AS linea_analisis
FROM
	item i
	LEFT JOIN linea l
	USING (id_linea,tipo)
	LEFT JOIN linea_has_linea_analisis lla
	ON lla.id_linea = LEFT( i.id_linea, 2 )
	LEFT JOIN linea_analisis la
	USING (id_linea_analisis)

WHERE
	i.estado = '0'
	AND LENGTH(i.descripcion) > 2
	AND i.id_sucursal = 'bog'

GROUP BY
	cod_item
