Modified the sql part of getConditionalDistributions.