Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql HEAP:删除重复的名称并在单个条目中添加这些值_Mysql - Fatal编程技术网

Mysql HEAP:删除重复的名称并在单个条目中添加这些值

Mysql HEAP:删除重复的名称并在单个条目中添加这些值,mysql,Mysql,我在MYSQL数据库中使用HEAP,我想获取数据,所以我使用下面的查询 select SUBSTRING (name, 1, CHARINDEX ('*' , name) - 1) as name, duration FROM ( SELECT b."identity" || '*' || session_id || '-' || a.user_id AS "name" ,MIN(time) AS "start" ,MAX

我在MYSQL数据库中使用HEAP,我想获取数据,所以我使用下面的查询

select SUBSTRING (name, 1, CHARINDEX ('*' , name) - 1) as name, duration
FROM (
           SELECT b."identity" || '*' || session_id || '-' || a.user_id AS "name"
             ,MIN(time) AS "start"
             ,MAX(time) AS "last"
           ,((DATEDIFF('milliseconds', MIN(time), MAX(time))::FLOAT / 1000  ) / 60) AS "duration"

     FROM abc_app_production.all_events a ,abc_app_production.users b
     where    a.user_id = b.user_id
     AND b.user_type IS NOT NULL
     AND b."identity" IS NOT NULL
     AND b."identity" NOT IN ('Shubham')
     AND time >= convert(datetime,'2018-10-01') AND time <= convert(datetime,'2018-11-01')
   GROUP BY 1
     )
但我想在一行中添加所有持续时间,重复如下:

name            duration

John            0.77
Butler          0.0
Tom             39.64
Kathi Mike      0.0
Manish          4.38

我试了很多,但都有错误。请提前提供帮助和感谢。

您需要总和聚合,但由于group by子句放置错误,因此出现了错误-它应该位于子查询之外

select SUBSTRING (name, 1, CHARINDEX ('*' , name) - 1) as name, sum(duration) as duration
FROM (
           SELECT b."identity" || '*' || session_id || '-' || a.user_id AS "name"
             ,MIN(time) AS "start"
             ,MAX(time) AS "last"
           ,((DATEDIFF('milliseconds', MIN(time), MAX(time))::FLOAT / 1000  ) / 60) AS "duration"

     FROM abc_app_production.all_events a ,abc_app_production.users b
     where    a.user_id = b.user_id
     AND b.user_type IS NOT NULL
     AND b."identity" IS NOT NULL
     AND b."identity" NOT IN ('Shubham')
     AND time >= convert(datetime,'2018-10-01') AND time <= convert(datetime,'2018-11-01') 
     group by b."identity" || '*' || session_id || '-' || a.user_id
)X group by SUBSTRING (name, 1, CHARINDEX ('*' , name) - 1)

感谢@fa06仍然获取错误:无效操作:列b.identity必须出现在GROUP BY子句中或在聚合函数中使用;
select SUBSTRING (name, 1, CHARINDEX ('*' , name) - 1) as name, sum(duration) as duration
FROM (
           SELECT b."identity" || '*' || session_id || '-' || a.user_id AS "name"
             ,MIN(time) AS "start"
             ,MAX(time) AS "last"
           ,((DATEDIFF('milliseconds', MIN(time), MAX(time))::FLOAT / 1000  ) / 60) AS "duration"

     FROM abc_app_production.all_events a ,abc_app_production.users b
     where    a.user_id = b.user_id
     AND b.user_type IS NOT NULL
     AND b."identity" IS NOT NULL
     AND b."identity" NOT IN ('Shubham')
     AND time >= convert(datetime,'2018-10-01') AND time <= convert(datetime,'2018-11-01') 
     group by b."identity" || '*' || session_id || '-' || a.user_id
)X group by SUBSTRING (name, 1, CHARINDEX ('*' , name) - 1)