How to alter a view sort order? I have used Views to create a view Display a summary by contextual filter. 

O/p



View settings like



Needs

There are only two option for sorting "ASC" or "DESC".

But i need to show like 

Pass(4)

Fail(2)

Waiting(1)

Tried for 

function hook_views_query_alter(){

}


But did not get how achieve this.

VIEW QUERY

SELECT field_data_field_bid_test.field_bid_test_value AS field_data_field_bid_test_field_bid_test_value, COUNT(crm_core_contact.contact_id) AS num_records
FROM 
{crm_core_contact} crm_core_contact
INNER JOIN {users} users_crm_core_contact ON crm_core_contact.uid = users_crm_core_contact.uid
LEFT JOIN {field_data_field_bid_test} field_data_field_bid_test ON crm_core_contact.contact_id = field_data_field_bid_test.entity_id AND (field_data_field_bid_test.entity_type = 'crm_core_contact' AND field_data_field_bid_test.deleted = '0')
GROUP BY field_data_field_bid_test_field_bid_test_value
ORDER BY field_data_field_bid_test_field_bid_test_value ASC
Yes finally i am able to solve this one.

Using 

function utility_views_query_alter(&amp;$view, &amp;$query) {

  if ($view-&gt;name == 'Viewname') {

    //dpm($view-&gt;query-&gt;orderby[0]);
 $view-&gt;query-&gt;orderby[0]['field'] = "CASE  field_data_field_bid_test_field_bid_test_value WHEN 'Pass' THEN 1 WHEN 'Fail' THEN 2 WHEN 'Waiting' THEN 3 ELSE 4 END";
  }
}