1

所以我现在正在为我们的开发人员填写(请注意我是初学者),但我试图简单地按包含个人资料图片的个人资料对我的搜索结果进行排序(即,我不想要空白的个人资料图片显示在结果的顶部......它们都应该在结果的末尾)......请注意,有几种用户类型,这就是为什么有这么多代码......

我很确定我要去哪里错是两条线......

ORDER BY $order u.picture ISNULL DESC"; (与按个人资料图片排序有关)。非常感谢任何和所有帮助...谢谢!

代码如下:

if ($user_type == 1) {
        $sql = "SELECT a.*, u.*,
                (SELECT COUNT(DISTINCT userId) FROM LF_usertype_A WHERE usertype_BId = u.userId AND status = 1) as i_cnt,
                (SELECT COUNT(productId) FROM LF_products WHERE userId = u.userId AND status = 1) as product_cnt,
                (SELECT COUNT(transactionId)
                    FROM LF_Transactions
                    WHERE usertypeBId = u.userId
                        AND (status = 1 OR status = 2)
                        AND type = 9
                        AND userId != usertypeBId
                        AND userId != usertypeAId) AS cnt
                FROM LF_Users u
                JOIN LF_products a ON a.userId = u.userId
                LEFT JOIN LF_Transactions t ON t.productId = a.productId
                WHERE a.status = 1
                    AND u.status = 1
                    AND u.userType = :ut $where
                GROUP BY u.userID
                ORDER BY $order u.name DESC LIMIT 200";
    } elseif ($filter != "recent" && $user_type == 2) {
        $sql = "SELECT u.*,
                (SELECT COUNT(a.productId) FROM LF_usertypeA a INNER JOIN LF_products ON a.productId = m.productId INNER JOIN LF_Users uu ON uu.userId = a.usertypeAId WHERE a.userId = u.userId AND uu.status = 1 AND a.status = 1 AND m.status = 1) as product_cnt,
                (SELECT COUNT(transactionId)
                    FROM LF_Transactions
                    WHERE usertypeBId = u.userId
                        AND (status = 1 OR status = 2)
                        AND type = 9
                        AND userId != usertypeAId
                        AND userId != usertypeBId) AS cnt
                FROM LF_Users u
                LEFT JOIN LF_Transactions t ON t.usertypeBId = u.userId
                WHERE u.status = 1
                    AND u.userId != 1
                    AND u.userType = :ut $where
                GROUP BY u.userID
                ORDER BY $order u.name DESC LIMIT 200
                ORDER BY $order u.picture ISNULL DESC";
    } else {
        $sql = "SELECT u.*,
                (SELECT COUNT(a.productId) FROM LF_usertype_A a INNER JOIN LF_products m ON a.productId = m.productId INNER JOIN LF_Users uu ON uu.userId = a.usertypeAId WHERE a.userId = u.userId AND uu.status = 1 AND a.status = 1 AND m.status = 1) as product_cnt,
                (SELECT COUNT(transactionId)
                    FROM LF_Transactions
                    WHERE usertypeBId = u.userId
                        AND (status = 1 OR status = 2)
                        AND type = 9
                        AND userId != usertypeAId
                        AND userId != usertypeBId) AS cnt
                FROM LF_Users u
                WHERE u.status = 1
                AND u.userId != 1
                AND u.userType = :ut $where
                GROUP BY u.userID
                ORDER BY $order u.name DESC LIMIT 200
        ORDER BY $order u.picture ISNULL DESC";
    }
4

1 回答 1

1

isnull如果您希望条件优先,则必须将条件放在常规排序顺序之前:

ORDER BY ISNULL(u.picture), $order
于 2012-04-20T17:28:20.033 回答