from_id and to_id using the LEAST function and alias it as person1.from_id and to_id using the GREATEST function and alias it as person2.COUNT(*) to calculate the number of calls between each pair and alias it as call_count.SUM(duration) to calculate the total duration of calls between each pair and alias it as total_duration.person1 and person2 to ensure that each pair is counted only once.erDiagram
Calls {
int from_id
int to_id
int duration
}