SQL server – SQL beginner trying to calculate the total time in minutes; need help with WHERE syntax error

I tried to calculate the total number of minutes that employees used in a system.
The data, stored under "Action" looks like something like below. Note that employees log on and log off several times a day.

| --------------------- | ------------------ | -------- ---------------- |
| empid | action | log_date |
| --------------------- | ------------------ | -------- ---------------- |
| a1 | ON | 2019-01-01T07: 00: 00.000Z |
| --------------------- | ------------------ | -------- ---------------- |
| a1 | OFF | 2019-01-01T07: 30: 00.000Z |
| --------------------- | ------------------ | -------- ---------------- |
| a1 | ON | 2019-01-01T08: 30: 00.000Z |
| --------------------- | ------------------ | -------- ---------------- |
| a1 | OFF | 2019-01-01T11: 30: 00.000Z |
| --------------------- | ------------------ | -------- ---------------- |
| a1 | ON | 2019-01-01T12: 30: 00.000Z |
| --------------------- | ------------------ | -------- ---------------- |
| a1 | OFF | 2019-01-01T12: 45: 00.000Z |
| --------------------- | ------------------ | -------- ---------------- |
| a2 | ON | 2019-01-01T08: 45: 00.000Z |
| --------------------- | ------------------ | -------- ---------------- |
| a2 | OFF | 2019-01-01T09: 15: 00.000Z |
| --------------------- | ------------------ | -------- ---------------- |
| a2 | ON | 2019-01-01T10: 00: 00.000Z |
| --------------------- | ------------------ | -------- ---------------- |
| a2 | OFF | 2019-01-01T11: 45: 00.000Z |
| --------------------- | ------------------ | -------- ---------------- |

Below is the SQL query code I worked on so far, but it returns "Request Error: Error: Syntax error equal to or near" WHERE ".

SELECT e.empid, CAST (e.log_date AS DATE) AS date,
SUM (DATEPART (CASE (e.log_date - s.log_date AS TIME)) AS as work_minutes
FROM (SELECT empid, log_date
Of the activity
WHERE action = ON & # 39;) AS s
JOIN (SELECT empid
Of the activity
WHERE action = OFF & # 39;) AS e
ON e.empid = s.empid
WHERE e.log_date = (SELECT log_date
Of the activity
LIMIT 1
O empid = e.empid
AND log_date> s.log_date)
GROUP BY e.empid, CAST (e.log_date AS DATE);

What seems to be the problem? I want the result of the query to look like this:

| --------------------- | ------------------ | -------- ---------------- |
| empid | date | minutes of work |
| --------------------- | ------------------ | -------- ---------------- |
| a1 | 2019-01-01 | 100 minutes |
| --------------------- | ------------------ | -------- ---------------- |
| b2 | 2019-01-01 | 150 minutes |
| --------------------- | ------------------ | -------- ---------------- |

(Work_minutes values ‚Äč‚Äčabove are random)

Any help is welcome.
Thank you!