我的存储过程报错,不知道什么原因
BEGINselectrealname,sum(bu)不满意,sum(yi)一般,sum(man)满意,sum(fei)非常满意from(selectrealname,0...
BEGIN
select realname,sum(bu) 不满意,sum(yi) 一般,sum(man) 满意,sum(fei) 非常满意 from
(
select realname,0 bu ,count(bug_id) yi,0 man,0 fei from (
SELECT bug_id,
(SELECT (SELECT realname FROM mantis_user_table WHERE id= handler_id) FROM mantis_bug_table WHERE id=bug_id)realname,
(SELECT (SELECT username FROM mantis_user_table WHERE id= handler_id) FROM mantis_bug_table WHERE id=bug_id)username,
new_value,
date_modified
FROM mantis_bug_history_table
WHERE field_name='服务评价'
and (SELECT (SELECT realname FROM mantis_user_table WHERE id= handler_id) FROM mantis_bug_table WHERE id=bug_id) is not null
and (SELECT (SELECT username FROM mantis_user_table WHERE id= handler_id) FROM mantis_bug_table WHERE id=bug_id) is not null
and date_modified>=startdate and date_modified<=enddate
) a
where new_value='一般'
group by realname
union
select realname,0 bu,0 yi,count(bug_id) man,0 fei from (
...................
where new_value='满意'
group by realname
union
select realname,0 bu,0 yi,0 man,count(bug_id) fei from (
...................
where new_value='非常满意'
group by realname
union
select realname,count(bug_id) bu ,0 yi,0 man,0 fei from (
SELECT bug_id,
..................
where new_value='不满意'
group by realname
) b
group by realname;
END;
-------------------------
报错信息如图所示 展开
select realname,sum(bu) 不满意,sum(yi) 一般,sum(man) 满意,sum(fei) 非常满意 from
(
select realname,0 bu ,count(bug_id) yi,0 man,0 fei from (
SELECT bug_id,
(SELECT (SELECT realname FROM mantis_user_table WHERE id= handler_id) FROM mantis_bug_table WHERE id=bug_id)realname,
(SELECT (SELECT username FROM mantis_user_table WHERE id= handler_id) FROM mantis_bug_table WHERE id=bug_id)username,
new_value,
date_modified
FROM mantis_bug_history_table
WHERE field_name='服务评价'
and (SELECT (SELECT realname FROM mantis_user_table WHERE id= handler_id) FROM mantis_bug_table WHERE id=bug_id) is not null
and (SELECT (SELECT username FROM mantis_user_table WHERE id= handler_id) FROM mantis_bug_table WHERE id=bug_id) is not null
and date_modified>=startdate and date_modified<=enddate
) a
where new_value='一般'
group by realname
union
select realname,0 bu,0 yi,count(bug_id) man,0 fei from (
...................
where new_value='满意'
group by realname
union
select realname,0 bu,0 yi,0 man,count(bug_id) fei from (
...................
where new_value='非常满意'
group by realname
union
select realname,count(bug_id) bu ,0 yi,0 man,0 fei from (
SELECT bug_id,
..................
where new_value='不满意'
group by realname
) b
group by realname;
END;
-------------------------
报错信息如图所示 展开
1个回答
展开全部
看提示信息, 好像数据库是 MySQL
MySQL 好像不像 Oracle / SQL Server 那种, 直接 BEGIN 中间是代码 END 就能执行的。
需要把那些代码,写到一个 存储过程里面
例如我写个最简单的
BEGIN
SELECT 'Hello World';
END
这么去执行,好像也是会报错的。
但是我这么写
CREATE PROCEDURE HelloWorld()
BEGIN
SELECT 'Hello World';
END
然后
call HelloWorld();
是可行的。
MySQL 好像不像 Oracle / SQL Server 那种, 直接 BEGIN 中间是代码 END 就能执行的。
需要把那些代码,写到一个 存储过程里面
例如我写个最简单的
BEGIN
SELECT 'Hello World';
END
这么去执行,好像也是会报错的。
但是我这么写
CREATE PROCEDURE HelloWorld()
BEGIN
SELECT 'Hello World';
END
然后
call HelloWorld();
是可行的。
参考资料: http://hi.baidu.com/wangzhiqing999/blog/item/0b145a84f1be9fd89023d961.html
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询