Create p_pivot_query