我有一个创建数据透视表的 MySQL SELECT。
SELECT t.*,
sum(HOUR(TIMEDIFF(STR_TO_DATE(Arbeitsbeginn, '%d.%m.%Y %H:%i:%s'),
STR_TO_DATE(Arbeitsende, '%d.%m.%Y %H:%i:%s')))) AS ARBEITSZEIT,
sum(HOUR(TIMEDIFF(STR_TO_DATE(Projektbeginn, '%d.%m.%Y %H:%i:%s'),
STR_TO_DATE(Projektende, '%d.%m.%Y %H:%i:%s')))) AS Projektzeit
FROM (SELECT DriverName,
Baustelle,
Arbeitsbeginn,
Arbeitsende,
Projektbeginn,
Projektende
FROM (SELECT DRIVERNAME,
GROUP_CONCAT(IF(ACTIONTEXT = 'PB', AREA, NULL)) AS 'Baustelle',
GROUP_CONCAT(IF(ACTIONTEXT = 'Arbeitsbeginn', DATETIME, NULL)) AS 'Arbeitsbeginn',
GROUP_CONCAT(IF(ACTIONTEXT = 'Arbeitsende', DATETIME, NULL)) AS 'Arbeitsende',
GROUP_CONCAT(IF(ACTIONTEXT = 'PB', DATETIME, NULL)) AS 'Projektbeginn',
GROUP_CONCAT(IF(ACTIONTEXT = 'PE', DATETIME, NULL)) AS 'Projektende'
FROM geoImportRoot
GROUP BY DRIVERNAME
) A CROSS JOIN
(SELECT 1 AS n UNION ALL SELECT 2) n
) t
GROUP BY DriverName;
检查这个小提琴:选择
问题是,我需要按日期分隔的数据,此时我将它们全部连续获取:
19.06.2013 09:09:01,19.06.2013 10:29:28,19.06.2013 14:01:11,20.06.2013 10:01:00
希望你能帮我解决这个问题。如果可能,请使用 SQL Fiddle