HAVING is not what you need - it is only useful if you want to filter MAX. For example, if you do not want to receive all MAXids, but only those that are greater than 2, you can use HAVING MAXid> 2.
As far as I understand, you want to ignore some lines and calculate the MAXid of the remaining lines. For this, your statement looks right to me. Afaiki position is not indicated in the result set if all its identifiers are indicated in your NOT IN clause. This is reasonable, since there is nothing that you could calculate MAX. If some of the item identifiers are specified in NOT IN and others are not , you should get MAX of those that are not specified in NOT IN.
If your result set does not match these conclusions, you should debug the line you insert into NOT IN - perhaps it contains too many identifiers.
source share