kept_suppliers = (restrict suppliers, lambda{ status > 10 }) with_countries = (join kept_suppliers, cities) supplying = (join with_countries, supplies) (summarize supplying, [:country], :which => collect{ pid }, :total => sum{ qty })