Drupal database and SQL
Solved

Finally I solved the problem with following codes 

$eid = $row-&gt;id; // a variable to store row id 
$sql = "SELECT SUM(field_past_std_date_value2 - field_past_std_date_value) as psd, field_std_pin_target_id as tid 
FROM field_data_field_pas_std_date d JOIN field_data_field_std_pin p ON d.entity_id = p.entity_id 
WHERE field_std_pin_target_id = $eid"; 


this bring me the total duration of past study of each student listed in my view. Although the problem is solved there may be better way to writer above squl. if anyone can give comments it will be highly appreciated. I'll continue improving my Drupal skills.