Query
SELECT o.id as obj_id, o.b_id, o.h_id, /*o.hc_id*/null as hc_id, o.ag_id, o.hscl_id, o.name_rus
,o.name, o.tp, o.country, o.code, c.name_rus country_name
,IFNULL(o.name_r, decline('r', o.name_rus, o.name, o.country)) as name_r
,IFNULL(o.name_p, decline('p', o.name_rus, o.name, o.country)) as name_p
,decline('d', o.name_rus, o.name, o.country) as name_d
,c.name_r as cntr_r
,c.name_p as cntr_p
,c.tp as country_tp
,case when o.name_rus is not null and ifnull(c.tp, 'q') != 'cis' then concat('(', o.name, ')') end as name2
,o.options
,o.hotel_qty
,o.hostel_qty
,/*o.hc_hotel_qty*/0 as hc_hotel_qty
,0 /*o.h_hotel_qty*/ as h_hotel_qty
,0/*o.hc_hostel_qty*/ as hc_hostel_qty
,o.bk_hotel_qty
,o.bk_hostel_qty
,o.add_hotel_qty
,o.add_hostel_qty
,o.hscl_hostel_qty
,o.ag_hotel_qty
,date_format(timestampadd(hour, -3, o.updated), '%a, %d %b %Y %k:%i:%s GMT') updated
,c.region
,c.ag_id cntr_ag_id
,b.ufi as book_ufi
,c.hscl_id as cntr_hscl_id
,c.tp as cntr_tp
,o.stars
,IFNULL(CASE WHEN o.iata_code IS NOT NULL THEN
(select count(fo.obj_id_to)
from fs_objs fo
where fo.obj_id_to = o.id
)
END, 0) has_flight
,IFNULL((select count(c.obj_id)
from ae_cities c
where c.obj_id = o.id
), 0) has_car
,IFNULL((select count(v.cntr)
from visas v
where v.cntr = o.country
), 0) has_visa
FROM objs o LEFT JOIN booking b ON (o.b_id = b.id)
,cntrs c
,obj_types ot
WHERE o.country = 'cities'
AND o.code = 'tarbert'
AND o.country = c.a2
AND ot.tp = o.tp
ORDER BY ot.ord, o.hotel_qty DESC failed: MySQL server has gone away