sql - mySQL, Stored Procedure, double COUNT not working (w/SQLfiddle) -
i have sql
select count( distinct `ct`.`content_type_id`) `type_count` , count(`content_id`) `content_count` `user_to_content` `uc` bring together `content` `c` using (`content_id`) bring together `content_type` `ct` using (`content_type_id`) `user_id`= 1;
i trying 2 numbers same table @ same time.
this sqlfiddle file shows above sql working...
however unable sp version work. can't seem sqlfiddle work sp (maybe can show me how), here sp @ pastebin...
anyway, sp not "compile" sec count command...
#1064 - have error in sql syntax; check manual corresponds mysql server version right syntax utilize near '' @ line 24
this line 24
declare $type_count tinyint(1) unsigned default 0;
my work around on phone call count on table twice. i'd rather not.
here's illustration modifications:
class="lang-sql prettyprint-override">delimiter $$ create procedure `sp_system_content_badges` ( in `$user_id` int(10) unsigned , in `$content_id` int(10) unsigned , in `$content_type_id` int(10) unsigned ) begin -- declare $type_count tinyint(1) unsigned default 0; -- declare $content_count tinyint(1) unsigned default 0; declare `$type_count` int unsigned default 0; declare `$content_count` int unsigned default 0; -- how many pieces of content has person consumed -- there 4 unique kinds -- select count( distinct `ct`.`content_type_id`) $type_count -- , count(`content_id`) $content_count select count(distinct `ct`.`content_type_id`), count(`c`.`content_id`) `$type_count`, `$content_count` `user_to_content` `uc` bring together `content` `c` using (`content_id`) bring together `content_type` `ct` using (`content_type_id`) `user_id`= `$user_id`; select `$type_count` 'type_count', `$content_count` 'content_count'; end$$ delimiter ;
sql fiddle example
mysql sql stored-procedures
No comments:
Post a Comment