This is a stab in the dark, but based on your updated comments I think I might know what you are dealing with. It seems like you are doing a sum and count on the order header level from the "orders" table, but by joining to the lines table you are getting multiple records, thus getting a seemingly arbitrary multiplication of both aggregates.
If this is the case, where you only want to sum and count the order header if there is one or more lines that meet your criteria (pCode in 1, 2, 3, 4) then what you want is a semi-join, using the exists clause.
SELECT
count(orders.id), sum(orders.total)
FROM
orders o
where
o.order_no like 'P%' and
exists (
select null
from orderItems i
where
o.order_no = i.order_no and
i.pCode in ('1', '2', '3', '4')
)
What this does is even if you have multiple lines meeting your condition(s), it will still only sum each header once. The syntax takes some getting used to, but the construct itself is very useful and efficient. The alternative would be a subquery "in" list, which on PostgreSQL would not run as efficiently for large datasets.
If that's not what you meant, please edit your question with the sample data and what you expect to see for the final output.