我有一个查询在两个字段FIELD_IMPORTANT和FIELD_2中搜索'字符串'。
我想得到结果;
如果在FIELD_IMPORTANT中找到'string',那么在TOP_的FIELD_IMPORTANT中记录具有'string'的记录的结果, 然后其他人......
有可能吗?
到目前为止,我有以下内容:
SELECT
expert.expert_name, naf_add.FIELD_IMPORTANT, naf_level_5.FIELD_2,
ROUND(AVG(expert_rating.rating_global)) AS avg_rating_global
FROM naf_nomenclature
LEFT JOIN naf_add ON naf_add.naf_add_naf_level_5_code = naf_nomenclature.level_5_code
INNER JOIN naf_level_5 ON naf_level_5.level_5_code = naf_nomenclature.level_5_code
INNER JOIN expert ON expert.expert_level_5_code = naf_nomenclature.level_5_code
LEFT JOIN expert_rating ON expert_rating.rating_expert_id = expert.expert_id
WHERE
naf_add.FIELD_IMPORTANT LIKE '%elec%' OR
naf_level_5.FIELD_2 LIKE '%elec%'
GROUP BY expert.expert_name
ORDER BY fword DESC, avg_rating_global DESC
答案 0 :(得分:1)
您可以在order by
:
order by (naf_add.FIELD_IMPORTANT LIKE '%elec%') desc,
fword, avg_rating_global
MySQL将布尔表达式视为数字上下文中的整数,使用" 0"为假和" 1"真的。因此,当表达式为真时,第一个键的值为" 1"。 desc
将这些放在第一位。