inflow and outflow query