select p.id as ID, pc.caption as "Группа", m.title as "Бренд",
p.title as "Товар", p.article as "Модель",
round(p.price::numeric, 2) as "Цена", round(p.input_price::numeric, 2) as "Опт",
round(((p.price - p.input_price)/p.price * 100)::numeric, 2) as "Рент. %",
round((p.price - p.input_price)::numeric, 2) as "Маржа",
ppr.title as "Поставщик",
pe.title as "Наличие",
(select string_agg(concat(round(pd.price::numeric, 2), ' ', cr.code, ' ', e.title,
' ост:', pd.exists_text, ' --> ', pr.title), chr(10))
from price_detail pd, price pr, curr cr, c_exists e where
pr.id = pd.price_id and pd.is_exists <> 2 and pr.price_type in (1, 3)
and pd.product_id = p.id
and pd.price_id <> p.price_id and cr.id = pd.price_curr_id and e.id = pd.is_exists)
as "Другие поставщики"
from product p, product_category pc, product_category_connect pcc,
c_manufacture m, price ppr, c_exists pe
where
pcc.prod_id = p.id and pcc.cat_id = pc.id and pcc.is_main = 1
and p.price_id = ppr.id and pe.id = p.is_exists
and m.code = p.manuf_code
and p.input_price > 0 and p.price > 0 and p.is_exists <> 2
and p.price_compare in (1,2)
and p.price - p.input_price >= 100
and (p.price - p.input_price)/p.price * 100 >= 30
order by p.price - p.input_price desc |