added logic to handle multilpe db types for grouip by sql