mysql选择不使用函数的情况

时间:2017-08-02 17:22:37

标签: mysql mysql-function

如何在image1变量中存储值

BEGIN
DECLARE image1 VARCHAR(250);
select case when (
            (
                select COUNT(*)
                from profile_images
                where building_id = bid
                    and contractor_id = cid
                ) > 0
            ) then (
                select distinct (image)
                into image1
                from profile_images
                where building_id = bid
                    and contractor_id = cid limit 1
                ) else (
            select distinct (image)
            into image1
            from profile_images
            where contractor_id = cid limit 1
            )

END
RETURN image1;
END

1 个答案:

答案 0 :(得分:1)

尝试:

BEGIN
DECLARE image1 VARCHAR(250);
select case when
            (
                select COUNT(*)
                from profile_images
                where building_id = bid
                    and contractor_id = cid
                ) > 0
              then (
                select distinct (image)
                -- into image1
                from profile_images
                where building_id = bid
                    and contractor_id = cid limit 1
                ) else (
            select distinct (image)
            -- into image1
            from profile_images
            where contractor_id = cid limit 1
            )
END into image1;
RETURN image1;
END