Group queries based on attributes.