string(1687) "
SELECT a.ID,
b.meta_value*1 as med_license,
c.meta_value as doctor_status ,e.meta_value as doctor_lic ,b.meta_value as doctor_med,
CASE when LEFT(e.meta_value,2) = 'ท.' OR b.meta_value = '9127' then 2
when LEFT(e.meta_value,2) = 'จ.' then 3 ELSE 1 END as Type
FROM wp_posts a
INNER JOIN wp_postmeta b ON a.ID = b.post_id AND b.meta_key = '_med_license_number'
INNER JOIN wp_postmeta c ON a.ID = c.post_id AND c.meta_key = '_doctor_staus_order'
INNER JOIN wp_postmeta d ON a.ID = d.post_id AND d.meta_key = '_internal_id'
INNER JOIN wp_postmeta e ON a.ID = e.post_id AND e.meta_key = '_med_license'
LEFT JOIN wp_term_relationships tr ON (a.ID = tr.object_id) LEFT JOIN wp_term_relationships tr2 ON (a.ID = tr2.object_id)
LEFT JOIN wp_term_relationships tr3 ON (a.ID = tr3.object_id)
WHERE a.post_status = 'publish'
AND a.post_type ='bch_doctor'
AND ( tr.term_taxonomy_id IN (25) ) AND ( tr2.term_taxonomy_id IN (22,29,27,24,135)
OR
tr3.term_taxonomy_id IN (434,290,291,457,285,448,62,66,137,60,64,68) OR ( d.meta_value IN (36181890,36181863,140389,36181924,36181909,170023,36181856,160105,140236,36181875,140690,140307,140240,160736,36181850,150986,36181828,140237,150758,36181889,160625,140227,150521,140233,140420) ) )
GROUP BY Type, doctor_status,doctor_lic,a.ID
ORDER BY Type ASC, doctor_status ASC, CAST(doctor_med AS SIGNED) ASC , doctor_med ASC "