Here's one way to write the SQL query:

```
SELECT 
  e.department_id, 
  e.name,
  DATEDIFF(NOW(), e.start_date) AS tenure_days
FROM employees e
WHERE NOT EXISTS (
  SELECT 1
  FROM employees e2
  WHERE e2.department_id = e.department_id
    AND DATEDIFF(NOW(), e2.start_date) > DATEDIFF(NOW(), e.start_date)
)
```

This query uses a subquery with `NOT EXISTS` to filter out rows where there exists another employee in the same department with a longer tenure. The main `SELECT` statement calculates the tenure of each employee in days using `DATEDIFF` and returns the department ID, employee name, and tenure.
Supponiamo di avere una tabella denominata &quot;employees&quot; con colonne &quot;employee_id&quot;, &quot;name&quot;, &quot;start_date&quot; e &quot;department_id&quot;. Scrivi una query SQL per trovare il dipendente con il mandato più lungo in ogni reparto.