add group by clause and use InstancesFrom