0

我有这个 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;

是否可以将其直接插入新表中?

4

1 回答 1

1

要从 select 语句创建一个表,您可以使用:

CREATE TABLE .... SELECT

它基本上是一个附加了CREATE TABLE语句的语句。SELECT


如果您希望将SELECT结果插入现有表中,请改用该INSERT ... SELECT语句。

于 2013-06-23T19:11:03.317 回答