我们从mysql中使用mysqldump把一个库导出来,带有6个视图,然后通过
mysql -u root -p -h 1.1.1.1 -P 4000 dbname < /xxx/xxx/dbname.sql导入了tidb
然后我们发现6个视图中,有一个没的导入,报了ERROR 1111 (HY000): Invalid use of group function
ccmc_view_tables_phone_status_time这个视图没有导入成功,手工在tidb中创建也报错了。
而ccmc_view_tables_text_status_time这个视图导入成功了。
这两个视图基本上是一样的,如下,我们通过diff的对比
两个 视图的定义如下:
CREATE ALGORITHM=UNDEFINED SQL SECURITY DEFINER VIEW ccmc_view_tables_text_status_time
AS select saas_cube_xyzphp
.tables
.code
AS tables_code
,saas_cube_xyzphp
.tables
.name
AS name
,saas_cube_xyzphp
.tables
.avatar
AS avatar
,reception
.serving_user_num
AS chat_busy
,saas_cube_xyzphp
.tables
.chat_limit
AS chat_limit
,saas_cube_xyzphp
.tables
.queue_limit
AS queue_limit
,saas_cube_xyzphp
.tables_infos
.job_position
AS job_position
,tables_groups
.name
AS group_name
,tables_status_time
.now_status
AS now_status
,tables_status_time
.now_keep_time
AS now_keep_time
,tables_status_time
.online_time
AS online_time
,tables_status_time
.offline_time
AS offline_time
,tables_status_time
.hangup_time
AS hangup_time
,tables_status_time
.acw_time
AS acw_time
,tables_status_time
.acw_num
AS acw_num
,tables_status_time
.callin_acw_time
AS callin_acw_time
,tables_status_time
.callin_acw_num
AS callin_acw_num
,tables_status_time
.callout_acw_time
AS callout_acw_time
,tables_status_time
.callout_acw_num
AS callout_acw_num
,tables_status_time
.hold_time
AS hold_time
,tables_status_time
.rest_time
AS rest_time
,tables_status_time
.rest_num
AS rest_num
,round((tables_status_time
.rest_time
/ tables_status_time
.login_time
),4) AS rest_rate
,tables_status_time
.call_time
AS call_time
,tables_status_time
.callin_time
AS callin_time
,tables_status_time
.callout_time
AS callout_time
,tables_status_time
.login_time
AS login_time
,tables_status_time
.now_at
AS now_at
,tables_status_time
.first_login_at
AS first_login_at
,tables_status_time
.first_logout_at
AS first_logout_at
,tables_status_time
.last_logout_at
AS last_logout_at
,tables_status_time
.first_offline_at
AS first_offline_at
,tables_status_time
.last_offline_at
AS last_offline_at
from ((((saas_cube_xyzphp
.tables
left join (select b
.tables_code
AS tables_code
,(select a
.current_status
from saas_cube_xyzphp
.tables_statuses
a
where (a
.id
= max(b
.id
))) AS now_status
,(unix_timestamp(now()) - unix_timestamp(max(b
.created_at
))) AS now_keep_time
,sum(if((b
.current_status
= ‘online’),if(isnull(b
.continuous_time
),(unix_timestamp(now()) - unix_timestamp(b
.created_at
)),b
.continuous_time
),0)) AS online_time
,sum(if((b
.current_status
= ‘offline’),if(isnull(b
.continuous_time
),(unix_timestamp(now()) - unix_timestamp(b
.created_at
)),b
.continuous_time
),0)) AS offline_time
,sum(if((b
.current_status
= ‘hangup’),if(isnull(b
.continuous_time
),(unix_timestamp(now()) - unix_timestamp(b
.created_at
)),b
.continuous_time
),0)) AS hangup_time
,sum(if((b
.current_status
= ‘acw’),if(isnull(b
.continuous_time
),(unix_timestamp(now()) - unix_timestamp(b
.created_at
)),b
.continuous_time
),0)) AS acw_time
,count(if((b
.current_status
= ‘acw’),TRUE,NULL)) AS acw_num
,sum(if(((b
.current_status
= ‘acw’) and (b
.last_status
= ‘callin’)),if(isnull(b
.continuous_time
),(unix_timestamp(now()) - unix_timestamp(b
.created_at
)),b
.continuous_time
),0)) AS callin_acw_time
,count(if(((b
.current_status
= ‘acw’) and (b
.last_status
= ‘callin’)),TRUE,NULL)) AS callin_acw_num
,sum(if(((b
.current_status
= ‘acw’) and (b
.last_status
= ‘callout’)),if(isnull(b
.continuous_time
),(unix_timestamp(now()) - unix_timestamp(b
.created_at
)),b
.continuous_time
),0)) AS callout_acw_time
,count(if(((b
.current_status
= ‘acw’) and (b
.last_status
= ‘callout’)),TRUE,NULL)) AS callout_acw_num
,sum(if((b
.current_status
= ‘hold’),if(isnull(b
.continuous_time
),(unix_timestamp(now()) - unix_timestamp(b
.created_at
)),b
.continuous_time
),0)) AS hold_time
,sum(if((b
.current_status
= ‘rest’),if(isnull(b
.continuous_time
),(unix_timestamp(now()) - unix_timestamp(b
.created_at
)),b
.continuous_time
),0)) AS rest_time
,count(if((b
.current_status
= ‘rest’),TRUE,NULL)) AS rest_num
,sum(if(((b
.current_status
= ‘callout’) or (b
.current_status
= ‘callin’)),if(isnull(b
.continuous_time
),(unix_timestamp(now()) - unix_timestamp(b
.created_at
)),b
.continuous_time
),0)) AS call_time
,sum(if((b
.current_status
= ‘callin’),if(isnull(b
.continuous_time
),(unix_timestamp(now()) - unix_timestamp(b
.created_at
)),b
.continuous_time
),0)) AS callin_time
,sum(if((b
.current_status
= ‘callout’),if(isnull(b
.continuous_time
),(unix_timestamp(now()) - unix_timestamp(b
.created_at
)),b
.continuous_time
),0)) AS callout_time
,sum(if(((b
.current_status
= ‘online’) or (b
.current_status
= ‘acw’) or (b
.current_status
= ‘hold’) or (b
.current_status
= ‘hangup’) or (b
.current_status
= ‘rest’) or (b
.current_status
= ‘callout’) or (b
.current_status
= ‘callin’) or (b
.current_status
= ‘offline’)),if(isnull(b
.continuous_time
),(unix_timestamp(now()) - unix_timestamp(b
.created_at
)),b
.continuous_time
),0)) AS login_time
,now() AS now_at
,min(if((b
.current_status
= ‘login’),b
.created_at
,NULL)) AS first_login_at
,min(if((b
.current_status
= ‘logout’),b
.created_at
,NULL)) AS first_logout_at
,max(if((b
.current_status
= ‘logout’),b
.created_at
,NULL)) AS last_logout_at
,min(if((b
.current_status
= ‘offline’),b
.created_at
,NULL)) AS first_offline_at
,max(if((b
.current_status
= ‘offline’),b
.created_at
,NULL)) AS last_offline_at
from saas_cube_xyzphp
.tables_statuses
b
where ((b
.created_at
> if((curtime() < ‘09:00:00’),date_format((curdate() - interval 1 day),‘%Y-%m-%d 18:00:00’),date_format(curdate(),‘%Y-%m-%d 00:00:00’))) and (b
.created_at
< if((curtime() < ‘09:00:00’),date_format(curdate(),‘%Y-%m-%d 09:00:00’),date_format((curdate() + interval 1 day),‘%Y-%m-%d 00:00:00’))) and (b
.type
= 1)) group by b
.tables_code
) tables_status_time
on((tables_status_time
.tables_code
= saas_cube_xyzphp
.tables
.code
))) left join (select saas_cube_xyzphp
.tables_reception_states
.serving_user_num
AS serving_user_num
,saas_cube_xyzphp
.tables_reception_states
.tables_code
AS tables_code
from saas_cube_xyzphp
.tables_reception_states
where ((saas_cube_xyzphp
.tables_reception_states
.created_at
> date_format(curdate(),‘%Y-%m-%d 00:00:00’)) and (saas_cube_xyzphp
.tables_reception_states
.created_at
<= date_format(curdate(),‘%Y-%m-%d 23:59:59’)))) reception
on((reception
.tables_code
= saas_cube_xyzphp
.tables
.code
))) left join saas_cube_xyzphp
.tables_infos
on((saas_cube_xyzphp
.tables_infos
.code
= saas_cube_xyzphp
.tables
.code
))) left join (select saas_cube_xyzphp
.tables_group
.code
AS code
,saas_cube_xyzphp
.groups
.id
AS id
,saas_cube_xyzphp
.groups
.name
AS name
from (saas_cube_xyzphp
.tables_group
left join saas_cube_xyzphp
.groups
on((saas_cube_xyzphp
.groups
.id
= saas_cube_xyzphp
.tables_group
.group_id
)))) tables_groups
on((tables_groups
.code
= saas_cube_xyzphp
.tables
.code
)))
这个成功了
CREATE ALGORITHM=UNDEFINED SQL SECURITY DEFINER VIEW ccmc_view_tables_phone_status_time
AS select saas_cube_xyzphp
.tables
.code
AS tables_code
,saas_cube_xyzphp
.tables
.name
AS name
,saas_cube_xyzphp
.tables
.avatar
AS avatar
,reception
.serving_user_num
AS chat_busy
,saas_cube_xyzphp
.tables
.chat_limit
AS chat_limit
,saas_cube_xyzphp
.tables
.queue_limit
AS queue_limit
,saas_cube_xyzphp
.tables_infos
.job_position
AS job_position
,tables_groups
.name
AS group_name
,tables_status_time
.now_status
AS now_status
,tables_status_time
.now_keep_time
AS now_keep_time
,tables_status_time
.online_time
AS online_time
,tables_status_time
.offline_time
AS offline_time
,tables_status_time
.hangup_time
AS hangup_time
,tables_status_time
.acw_time
AS acw_time
,tables_status_time
.acw_num
AS acw_num
,tables_status_time
.callin_acw_time
AS callin_acw_time
,tables_status_time
.callin_acw_num
AS callin_acw_num
,tables_status_time
.callout_acw_time
AS callout_acw_time
,tables_status_time
.callout_acw_num
AS callout_acw_num
,tables_status_time
.hold_time
AS hold_time
,tables_status_time
.rest_time
AS rest_time
,tables_status_time
.rest_num
AS rest_num
,round((tables_status_time
.rest_time
/ tables_status_time
.login_time
),4) AS rest_rate
,tables_status_time
.call_time
AS call_time
,tables_status_time
.callin_time
AS callin_time
,tables_status_time
.callout_time
AS callout_time
,tables_status_time
.login_time
AS login_time
,tables_status_time
.now_at
AS now_at
,tables_status_time
.first_login_at
AS first_login_at
,tables_status_time
.first_logout_at
AS first_logout_at
,tables_status_time
.last_logout_at
AS last_logout_at
,tables_status_time
.first_offline_at
AS first_offline_at
,tables_status_time
.last_offline_at
AS last_offline_at
from ((((saas_cube_xyzphp
.tables
left join (select b
.tables_code
AS tables_code
,(select a
.current_status
from saas_cube_xyzphp
.tables_statuses
a
where (a
.id
= max(b
.id
))) AS now_status
,(unix_timestamp(now()) - unix_timestamp(max(b
.created_at
))) AS now_keep_time
,sum(if((b
.current_status
= ‘online’),if(isnull(b
.continuous_time
),(unix_timestamp(now()) - unix_timestamp(b
.created_at
)),b
.continuous_time
),0)) AS online_time
,sum(if((b
.current_status
= ‘offline’),if(isnull(b
.continuous_time
),(unix_timestamp(now()) - unix_timestamp(b
.created_at
)),b
.continuous_time
),0)) AS offline_time
,sum(if((b
.current_status
= ‘hangup’),if(isnull(b
.continuous_time
),(unix_timestamp(now()) - unix_timestamp(b
.created_at
)),b
.continuous_time
),0)) AS hangup_time
,sum(if((b
.current_status
= ‘acw’),if(isnull(b
.continuous_time
),(unix_timestamp(now()) - unix_timestamp(b
.created_at
)),b
.continuous_time
),0)) AS acw_time
,count(if((b
.current_status
= ‘acw’),TRUE,NULL)) AS acw_num
,sum(if(((b
.current_status
= ‘acw’) and (b
.last_status
= ‘callin’)),if(isnull(b
.continuous_time
),(unix_timestamp(now()) - unix_timestamp(b
.created_at
)),b
.continuous_time
),0)) AS callin_acw_time
,count(if(((b
.current_status
= ‘acw’) and (b
.last_status
= ‘callin’)),TRUE,NULL)) AS callin_acw_num
,sum(if(((b
.current_status
= ‘acw’) and (b
.last_status
= ‘callout’)),if(isnull(b
.continuous_time
),(unix_timestamp(now()) - unix_timestamp(b
.created_at
)),b
.continuous_time
),0)) AS callout_acw_time
,count(if(((b
.current_status
= ‘acw’) and (b
.last_status
= ‘callout’)),TRUE,NULL)) AS callout_acw_num
,sum(if((b
.current_status
= ‘hold’),if(isnull(b
.continuous_time
),(unix_timestamp(now()) - unix_timestamp(b
.created_at
)),b
.continuous_time
),0)) AS hold_time
,sum(if((b
.current_status
= ‘rest’),if(isnull(b
.continuous_time
),(unix_timestamp(now()) - unix_timestamp(b
.created_at
)),b
.continuous_time
),0)) AS rest_time
,count(if((b
.current_status
= ‘rest’),TRUE,NULL)) AS rest_num
,sum(if(((b
.current_status
= ‘callout’) or (b
.current_status
= ‘callin’)),if(isnull(b
.continuous_time
),(unix_timestamp(now()) - unix_timestamp(b
.created_at
)),b
.continuous_time
),0)) AS call_time
,sum(if((b
.current_status
= ‘callin’),if(isnull(b
.continuous_time
),(unix_timestamp(now()) - unix_timestamp(b
.created_at
)),b
.continuous_time
),0)) AS callin_time
,sum(if((b
.current_status
= ‘callout’),if(isnull(b
.continuous_time
),(unix_timestamp(now()) - unix_timestamp(b
.created_at
)),b
.continuous_time
),0)) AS callout_time
,sum(if(((b
.current_status
= ‘online’) or (b
.current_status
= ‘acw’) or (b
.current_status
= ‘hold’) or (b
.current_status
= ‘hangup’) or (b
.current_status
= ‘rest’) or (b
.current_status
= ‘callout’) or (b
.current_status
= ‘callin’) or (b
.current_status
= ‘offline’)),if(isnull(b
.continuous_time
),(unix_timestamp(now()) - unix_timestamp(b
.created_at
)),b
.continuous_time
),0)) AS login_time
,now() AS now_at
,min(if((b
.current_status
= ‘login’),b
.created_at
,NULL)) AS first_login_at
,min(if((b
.current_status
= ‘logout’),b
.created_at
,NULL)) AS first_logout_at
,max(if((b
.current_status
= ‘logout’),b
.created_at
,NULL)) AS last_logout_at
,min(if((b
.current_status
= ‘offline’),b
.created_at
,NULL)) AS first_offline_at
,max(if((b
.current_status
= ‘offline’),b
.created_at
,NULL)) AS last_offline_at
from saas_cube_xyzphp
.tables_statuses
b
where ((b
.created_at
> if((curtime() < ‘09:00:00’),date_format((curdate() - interval 1 day),‘%Y-%m-%d 18:00:00’),date_format(curdate(),‘%Y-%m-%d 00:00:00’))) and (b
.created_at
< if((curtime() < ‘09:00:00’),date_format(curdate(),‘%Y-%m-%d 09:00:00’),date_format((curdate() + interval 1 day),‘%Y-%m-%d 00:00:00’))) and (b
.type
= 2)) group by b
.tables_code
) tables_status_time
on((tables_status_time
.tables_code
= saas_cube_xyzphp
.tables
.code
))) left join (select saas_cube_xyzphp
.tables_reception_states
.serving_user_num
AS serving_user_num
,saas_cube_xyzphp
.tables_reception_states
.tables_code
AS tables_code
from saas_cube_xyzphp
.tables_reception_states
where ((saas_cube_xyzphp
.tables_reception_states
.created_at
> date_format(curdate(),‘%Y-%m-%d 00:00:00’)) and (saas_cube_xyzphp
.tables_reception_states
.created_at
<= date_format(curdate(),‘%Y-%m-%d 23:59:59’)))) reception
on((reception
.tables_code
= saas_cube_xyzphp
.tables
.code
))) left join saas_cube_xyzphp
.tables_infos
on((saas_cube_xyzphp
.tables_infos
.code
= saas_cube_xyzphp
.tables
.code
))) left join (select saas_cube_xyzphp
.tables_group
.code
AS code
,saas_cube_xyzphp
.groups
.id
AS id
,saas_cube_xyzphp
.groups
.name
AS name
from (saas_cube_xyzphp
.tables_group
left join saas_cube_xyzphp
.groups
on((saas_cube_xyzphp
.groups
.id
= saas_cube_xyzphp
.tables_group
.group_id
)))) tables_groups
on((tables_groups
.code
= saas_cube_xyzphp
.tables
.code
)))
这个不成功