There is no way to use orm here (if we want to make this in one query). To use orm we'll have to iterate through all devices and check if in period of time it's dailydevices ventures are different - but this sucks and will be so much slooooow. Besides that - this query is quite simple and well explained imo.