string(1132) "
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)
WHERE a.post_status = 'publish'
AND a.post_type ='bch_doctor'
AND ( tr.term_taxonomy_id IN (48) )
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 "