postgre crosstab函数 查询条件传入变量写法

 SELECT * FROM crosstab('
SELECT stockstatus.product_id_,
 
stockstatus.product_stock_status_type_id_,
stockstatus.quantity_
FROM product_stock_status stockstatus
left join product prod on stockstatus.product_id_ = prod.product_id_
left join product_category_info middleCateInfo on middleCateInfo.product_id_ = stockstatus.product_id_
and middleCateInfo.site_id_ = '''||siteid||'''
and middleCateInfo.product_category_type_id_ = ''PARTMIDDLEGROUP''
left join product_category_info largeCateInfo on largeCateInfo.product_id_ = stockstatus.product_id_
and largeCateInfo.site_id_ = '''||siteid||'''
and largeCateInfo.product_category_type_id_ = ''PARTLARGEGROUP''

WHERE stockstatus.site_id_ = '''||siteid||'''
AND stockstatus.facility_id_ = '''||pointid||'''
AND stockstatus.product_classification_id_ = ''C059PART''
AND stockstatus.quantity_ > 0
order by 1,2
'
,$$values('C071ONHANDQTY' :: text),
('C071A' :: text),
('C071B' :: text),
('C071ONR' :: text),
('C071ONF' :: text)
$$)
AS ProductStock(product_Id_ VARCHAR(40),
onHand numeric(18,2),
allocated numeric(18,2),
bo numeric(18,2), onF numeric(18,2));

你可能感兴趣的:(postgre crosstab函数 查询条件传入变量写法)