$as247 = Yii::app()->db->createCommand()
->select('id')
->from('tbl_services asv')
->where('user_id=:user_id AND (SELECT count(*) FROM `tbl_workdays` wdv
WHERE `asv`.`id` = `wdv`.`service_id`) = 7 AND (SELECT `id` from `tbl_workhours` whv
WHERE `whv`.`start_id`=1 AND `whv`.`end_id`=25 AND `whv`.`service_id` = `asv`.`id`)', array(':user_id'=>$id))
->order('id')
->limit('1')
->queryRow();