select
pppp.id,
pppp.pens_product_id,
pppp.value_int,
pppp.value_decimal,
pppp.value_string,
pppp.value_ref
from prod_line.pens_product_param_pl pppp
join prod_line.param_pl pp
on pp.id = pppp.param_pl_id
where pp.brief = 'АНД'
and (
pppp.value_int is not null
or pppp.value_decimal is not null
or pppp.value_ref is not null
or (
pppp.value_string is not null
and trim(pppp.value_string) <> ''
and lower(trim(pppp.value_string)) <> 'не установлена'
)
)
order by pppp.pens_product_id desc
limit 50;