MDL-38753 tweak count SQL to make stupid Oracle happy