0
如果我沒有錯誤,當使用有,查詢執行沒有任何過濾器,然後代碼遍歷所有結果應用過濾器。但在這種情況下,我使用多個贊//如果計算我的訂單。我想知道什麼之間會更好:WHERE vs HAVING計算字段與多個IF/LIKE
SELECT Page.*,
if (`flags` LIKE CONCAT('%',?,'%'),
if (`title` LIKE CONCAT('%',?,'%'),
5,
3
),
if (`title` LIKE CONCAT('%',?,'%'),
2,
0
),
) as pageOrder
FROM Page
WHERE `flags` LIKE CONCAT('%',?,'%') OR `title` LIKE CONCAT('%',?,'%')
ORDER BY pageOrder DESC
或
SELECT Page.*,
if (`flags` LIKE CONCAT('%',?,'%'),
if (`title` LIKE CONCAT('%',?,'%'),
5,
3
),
if (`title` LIKE CONCAT('%',?,'%'),
2,
0
),
) as pageOrder
FROM Page
HAVING pageOrder > 0
ORDER BY pageOrder DESC
用mysql 5.7和PHP 7.1