正在尝试编写一个查询,其中我正在为upvote和downvote检索用户的状态

3ks5zfa0  于 2021-07-26  发布在  Java
关注(0)|答案(0)|浏览(159)

我试图运行一个查询,但我无法得到它的权利,试图写一个查询,其中我是检索用户的状态为upvote和downvote如果该特定的职位既没有upvote或downvote它应该返回-1

if ($feature == 'all' || $feature == 'article')
            {
                // $g_article = DB::table('mst_article as a')->leftJoin('trans_article_group as ag', 'a.id', '=', 'ag.article_id_fk')->select('a.id', 'user_id_fk as user_id', 'a.title', 'a.description', 'a.created_at', 'cover_type', 'profile_image as image', DB::raw('"article" as type'))->where('group_id_fk', $group_id)->where('a.status', '1');
                $g_article = DB::table('mst_article as e');
                $g_article->join('trans_article_group as g', 'g.article_id_fk', '=', 'e.id', 'left');
                $g_article->join('mst_group as grp', 'grp.id', '=', 'g.group_id_fk', 'left');
                $g_article->join('trans_follow_user as f', 'f.user_id_fk', '=', 'e.user_id_fk', 'left');
                $g_article->join('mst_users as u', 'u.id', '=', 'e.user_id_fk');
                $g_article->select('e.id', 'e.user_id_fk as user_id', 'e.title', 'e.description', 'e.created_at', 'e.cover_type', 'e.profile_image as image', DB::raw('"article" as type'),
                DB::raw('(SELECT CASE WHEN `ud`.`article_id_fk` = `p1036_e`.`id` AND `ud`.`user_id_fk` = ' . $user_id . ' AND `ud`.`status` = "0" THEN "0" ELSE "-1" END ) AS user_upvote_status FROM `p1036_trans_article_upvote_downvote` AS `ud`'),
                DB::raw('(SELECT CASE WHEN `ud`.`article_id_fk` = `p1036_e`.`id` AND `ud`.`user_id_fk` = ' . $user_id . ' AND `ud`.`status` = "1" THEN "1" ELSE "-1" END )AS user_downvote_status FROM `p1036_trans_article_upvote_downvote` AS `ud` '))->where('e.status','1')->where('group_id_fk', $group_id);
            }

这是查询
我的主要目标是这两条线

DB::raw('(SELECT CASE WHEN `ud`.`article_id_fk` = `p1036_e`.`id` AND `ud`.`user_id_fk` = ' . $user_id . ' AND `ud`.`status` = "0" THEN "0" ELSE "-1" END ) AS user_upvote_status FROM `p1036_trans_article_upvote_downvote` AS `ud`'),
                DB::raw('(SELECT CASE WHEN `ud`.`article_id_fk` = `p1036_e`.`id` AND `ud`.`user_id_fk` = ' . $user_id . ' AND `ud`.`status` = "1" THEN "1" ELSE "-1" END ) AS user_downvote_status FROM `p1036_trans_article_upvote_downvote` AS `ud` ')

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题