Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SELECT DISTINCT(s.id), s.name, s.max_itinerary_length, s.permalink FROM
- ((SELECT t.id, t.name, t.max_itinerary_length, t.permalink, count(ta.id) as tagcount
- FROM tours t
- INNER JOIN brochure_tours bt ON bt.tour_id = t.id
- INNER JOIN tour_variations tv ON tv.brochure_tour_id = bt.id
- INNER JOIN highlight_tour_places htp ON htp.brochure_tour_id = bt.id
- INNER JOIN highlight_groups hg ON hg.highlight_tour_place_id = htp.id
- INNER JOIN highlights h ON hg.highlight_id = h.id
- INNER JOIN taggings tas
- ON (tas.taggable_type = 'Highlight' AND tas.taggable_id = h.id)
- INNER JOIN tags ta
- ON tas.tag_id = ta.id
- WHERE tv.selling_company_id = 1
- AND ta.name IN ('berlin','germany','europe','tiergarten','alexanderplatz','russian war memorial','brandenburg gate','the reichstag','reichstag','berlin wall','the berlin wall','dresden','zwinger','prague','czech republic','hradcany castle','st vitus','charles bridge','wenceslas square','prague old town square','astronomical clock','berlin historical walking tour','walking tour','germnay','berlin walking tour','optional excursions','luch cruise','lunchtime crusie','traditional czech evening','prague dinner')
- GROUP BY t.id)
- UNION
- (SELECT t.id, t.name, t.max_itinerary_length, t.permalink, count(ta.id) as tagcount
- FROM tours t
- INNER JOIN brochure_tours bt ON bt.tour_id = t.id
- INNER JOIN tour_variations tv ON tv.brochure_tour_id = bt.id
- INNER JOIN optional_tour_places otp ON otp.brochure_tour_id = bt.id
- INNER JOIN optional_groups og ON og.optional_tour_place_id = otp.id
- INNER JOIN optionals o ON og.optional_id = o.id
- INNER JOIN taggings tas
- ON (tas.taggable_type = 'Optional' AND tas.taggable_id = o.id)
- INNER JOIN tags ta
- ON tas.tag_id = ta.id
- WHERE tv.selling_company_id = 1
- AND ta.name IN ('berlin','germany','europe','tiergarten','alexanderplatz','russian war memorial','brandenburg gate','the reichstag','reichstag','berlin wall','the berlin wall','dresden','zwinger','prague','czech republic','hradcany castle','st vitus','charles bridge','wenceslas square','prague old town square','astronomical clock','berlin historical walking tour','walking tour','germnay','berlin walking tour','optional excursions','luch cruise','lunchtime crusie','traditional czech evening','prague dinner')
- GROUP BY t.id)) s
- ORDER BY tagcount DESC
- LIMIT 4
Add Comment
Please, Sign In to add comment