创建表su AS选择不起作用

时间:2016-03-06 13:49:00

标签: mysql

我有这张桌子

ID  |user       |Contact   |Duration
1    asif        11         00
2    bob         22         65
3    cena        33         00
4    asif        44         00
5    cena        33         00
6    cena        33         00
7    bob         55         43
8    asif        44         33
9    bob         66         00

我想使用这个sql;

CREATE TABLE su
AS (select user, 
      contactcount,
      duration,
      case when durationcount = 0 then 0 else duration/durationcount end
from (
   select user, 
          count(distinct contact) contactcount,
          sum(duration) duration,
          sum(case when duration > 0 then 1 else 0 end) durationcount
   from table4
   group by user
) t)

但是phpmyadmin,给出错误。 #1166 - Incorrect column name 'case when durationcount = 0 then 0 else duration/durationcount end' 预期的产量;

|user      |count   |duration_total    |case when durationcount = 0 then 0 else duration/durationcount end
 asif       2        33                 33
 bob        3        108                54
 cena       1        00                 00

这个sql中的wromg是什么? 目标是在持续时间> 0

时创建新的表格ID,用户,每个用户的总持续时间和用户的平均时间

0 个答案:

没有答案