def _ProcessCcSD(fmt):
  """Convert a 'cc' sort directive into SQL."""
  # Note: derived cc's are included automatically.
  # Note: This sorts on the best Cc, not all Cc addresses.
  # Being more exact might require GROUP BY and GROUP_CONCAT().
  left_joins = [
      (fmt('Issue2Cc AS {alias} ON Issue.id = {alias}.issue_id '
           'LEFT JOIN User AS {alias}_user '
           'ON {alias}.cc_id = {alias}_user.user_id'), [])]
  order_by = [
      (fmt('ISNULL({alias}_user.email) {sort_dir}'), []),
      (fmt('{alias}_user.email {sort_dir}'), [])]
  return left_joins, order_by