Skip to content

Instantly share code, notes, and snippets.

@shannah
Created June 25, 2014 22:51
Show Gist options
  • Save shannah/ed4cbab82f38bc6ae35b to your computer and use it in GitHub Desktop.
Save shannah/ed4cbab82f38bc6ae35b to your computer and use it in GitHub Desktop.
create view contact_call_info as select c.contact_id,
(select count(*) from calls where contact_id=c.contact_id) as num_calls,
(select call_result from calls where contact_id=c.contact_id order by time_of_call desc limit 1) as last_call_result,
(select max(time_of_call) from calls where contact_id=c.contact_id) as last_call_time,
(select student_decision from calls where contact_id=c.contact_id order by time_of_call desc limit 1) as last_student_decision,
(select mentor_preference_id from calls where contact_id=c.contact_id order by time_of_call desc limit 1) as last_mentor_pref,
(select group_concat(caller_comments) from calls where contact_id=c.contact_id) as combined_caller_comments
from current_call_list c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment