Count of open Tasks in BPM for the current user

I want to have a count of open tasks in BPM for the current user and trying the following query but seems it’s missing something:

dataManager.loadValue(
"select count(e) from bpm$ProcTask e join e.procInstance i " +
        "where e.outcome is null and i in (select a.procInstance from bpm$ProcActor a where a.userId = :userId)", Integer.class)

But when I use the following query it returns all users open tasks though

select count(e) from bpm$ProcTask e join e.procInstance i 
            where e.outcome is null ", Integer.class)  

I might have been missing something in joining any Entity. Thanks for any help.

Try something like this:

select count(pt) from bpm$ProcTask pt join pt.procActor pa join pa.user pau 
where pau.id = :userId and pt.endDate is null

Thank you Max