我在mysql与data studio的结合中遇到了以下问题,坦率地说,我很困惑:
SELECT
user.name,
user.second_name,
school.name,
SUM(booked_lessons.duration),
SUM(total_lessons.duration),
SUM(theory_lessons.duration)
FROM
lesson
LEFT JOIN
user ON lesson.instructor_id = user.id
LEFT JOIN
school ON lesson.school_id = school.id
LEFT JOIN
(SELECT
lesson.id, lesson.duration
FROM
lesson
WHERE
lesson.status = 'active'
AND entity = 'driving'
AND lesson.user_id IS NOT NULL) AS booked_lessons ON booked_lessons.id = lesson.id
LEFT JOIN
(SELECT
lesson.id, lesson.duration
FROM
lesson
WHERE
lesson.status = 'active'
AND entity = ('driving' OR 'theory' OR 'exam')) AS total_lessons ON total_lessons.id = lesson.id
LEFT JOIN
(SELECT
lesson.id, lesson.duration
FROM
lesson
WHERE
lesson.status = 'active'
AND entity = 'theory') AS theory_lessons ON theory_lessons.id = lesson.id
WHERE
lesson.startDate >= '2018-01-31 00:00:00'
AND lesson.startDate <= '2019-01-06 23:59:59'
GROUP BY lesson.instructor_id;`
当我将import代码作为mysql数据源包含在googledatastudio中时,一开始一切似乎都很顺利。然而,当我想分析图表中的数据时,我得到了以下错误消息:错误1
更令人困惑的是:
当我使用此代码时:
`SELECT
user.name 'Vorname',
user.second_name 'Nachname',
lesson.instructor_id 'FL ID',
school.name 'Standort',
SUM(offered_lessons.duration) 'noch buchbare Praxisstunden',
SUM(booked_lessons.duration) 'gebuchte Praxisstunden',
SUM(total_week_lessons.duration) 'angebotene Praxis gesamt',
SUM(theory_lessons.duration) 'Theorieunterricht',
SUM(exam_lessons.duration) 'Prüfungen',
SUM(total_lessons.duration) 'angebotene Stunden gesamt',
SUM(activity_lessons.duration) 'Sonstige Tätigkeiten',
SUM(canceled_lessons.duration) 'abgesagt von 123 <48',
SUM(canceled_48_lessons.duration) 'abgesagt von 123 >48',
SUM(canceled_student_lessons.duration) 'abgesagt von Schueler <48',
SUM(canceled_48_student_lessons.duration) 'abgesagt von Schueler >48',
SUM(canceled_instructor_lessons.duration) 'abgesagt von FL <48',
SUM(canceled_48_instructor_lessons.duration) 'abgesagt von FL >48'
FROM
lesson
LEFT JOIN
user ON lesson.instructor_id = user.id
LEFT JOIN
school ON lesson.school_id = school.id
LEFT JOIN
(SELECT
lesson.id, lesson.duration
FROM
lesson
WHERE
lesson.status = 'active'
AND entity = 'driving'
AND lesson.user_id IS NULL) AS offered_lessons ON offered_lessons.id = lesson.id
LEFT JOIN
(SELECT
lesson.id, lesson.duration
FROM
lesson
WHERE
lesson.status = 'active'
AND entity = 'driving'
AND lesson.user_id IS NOT NULL) AS booked_lessons ON booked_lessons.id = lesson.id
LEFT JOIN
(SELECT
lesson.id, lesson.duration
FROM
lesson
WHERE
lesson.status = 'active'
AND entity = 'driving') AS total_week_lessons ON total_week_lessons.id = lesson.id
LEFT JOIN
(SELECT
lesson.id, lesson.duration
FROM
lesson
WHERE
lesson.status = 'active'
AND entity = ('driving' OR 'theory' OR 'exam')) AS total_lessons ON total_lessons.id = lesson.id
LEFT JOIN
(SELECT
lesson.id, lesson.duration
FROM
lesson
WHERE
lesson.status = 'active'
AND entity = 'theory') AS theory_lessons ON theory_lessons.id = lesson.id
LEFT JOIN
(SELECT
lesson.id, lesson.duration
FROM
lesson
WHERE
lesson.status = 'active'
AND entity = 'exam') AS exam_lessons ON exam_lessons.id = lesson.id
LEFT JOIN
(SELECT
lesson.id, lesson.duration
FROM
lesson
WHERE
lesson.status = 'active'
AND entity = 'activity') AS activity_lessons ON activity_lessons.id = lesson.id
LEFT JOIN
(SELECT
lesson.id,
lesson.duration,
TIMESTAMPDIFF(HOUR, lesson.cancelled_at, lesson.startDate)
FROM
lesson
WHERE
lesson.status = 'canceled'
AND entity = 'driving'
AND TIMESTAMPDIFF(HOUR, lesson.cancelled_at, lesson.startDate) < 48
AND user_Id != lesson.cancelled_by_id) AS canceled_lessons ON canceled_lessons.id = lesson.id
LEFT JOIN
(SELECT
lesson.id,
lesson.duration,
TIMESTAMPDIFF(HOUR, lesson.cancelled_at, lesson.startDate)
FROM
lesson
WHERE
lesson.status = 'canceled'
AND entity = 'driving'
AND TIMESTAMPDIFF(HOUR, lesson.cancelled_at, lesson.startDate) >= 48
AND user_Id != lesson.cancelled_by_id) AS canceled_48_lessons ON canceled_48_lessons.id = lesson.id
LEFT JOIN
(SELECT
lesson.id,
lesson.duration,
TIMESTAMPDIFF(HOUR, lesson.cancelled_at, lesson.startDate)
FROM
lesson
WHERE
lesson.status = 'canceled'
AND entity = 'driving'
AND TIMESTAMPDIFF(HOUR, lesson.cancelled_at, lesson.startDate) < 48
AND user_Id = lesson.cancelled_by_id) AS canceled_student_lessons ON canceled_student_lessons.id = lesson.id
LEFT JOIN
(SELECT
lesson.id,
lesson.duration,
TIMESTAMPDIFF(HOUR, lesson.cancelled_at, lesson.startDate)
FROM
lesson
WHERE
lesson.status = 'canceled'
AND entity = 'driving'
AND TIMESTAMPDIFF(HOUR, lesson.cancelled_at, lesson.startDate) >= 48
AND user_Id = lesson.cancelled_by_id) AS canceled_48_student_lessons ON canceled_48_student_lessons.id = lesson.id
LEFT JOIN
(SELECT
lesson.id,
lesson.duration,
TIMESTAMPDIFF(HOUR, lesson.cancelled_at, lesson.startDate)
FROM
lesson
WHERE
lesson.status = 'canceled'
AND entity = 'driving'
AND TIMESTAMPDIFF(HOUR, lesson.cancelled_at, lesson.startDate) < 48
AND instructor_Id = lesson.cancelled_by_id) AS canceled_instructor_lessons ON canceled_instructor_lessons.id = lesson.id
LEFT JOIN
(SELECT
lesson.id,
lesson.duration,
TIMESTAMPDIFF(HOUR, lesson.cancelled_at, lesson.startDate)
FROM
lesson
WHERE
lesson.status = 'canceled'
AND entity = 'driving'
AND TIMESTAMPDIFF(HOUR, lesson.cancelled_at, lesson.startDate) >= 48
AND Instructor_Id = lesson.cancelled_by_id) AS canceled_48_instructor_lessons ON canceled_48_instructor_lessons.id = lesson.id
WHERE
lesson.startDate >= '2018-01-31 00:00:00'
AND lesson.startDate <= '2019-01-06 23:59:59'
GROUP BY lesson.instructor_id;
`代码几乎相同。但现在我得到一个错误信息:
错误2
有人能帮帮我吗?
提前谢谢。
2条答案
按热度按时间z9zf31ra1#
在子查询的末尾,就在前面有分号吗
ct3nt3jp2#
不能用分号(;)因为datastudio在生成数据时会向查询中添加代码。
有同样的问题,删除分号,现在报告正在工作。