php - SQL order by total of value by rows
问题描述
有没有一种方法可以返回包含行中的总列值,以按示例将其用于排序:
id | title | body_text_1 | body_text_2 | body_text_3 |
---------------------------------------------------------------------------------------------
1 | History | book of History | movies | Image |
2 | Sport | history | book | Audio |
3 | Cinema | History | History | History |
4 | History | classic | History | Audio |
我正在使用 LIKE %value% 如果我搜索单词History 结果将 id 3 显示为第一个,因为它在 3 列中有历史记录
第二个将是 1 和 4,因为它在 2 列中有历史记录
最后一个将是 2 因为它只在一列中有历史
结果 :
3
1
4
2
解决方案
您可以将布尔值添加到order by
:
order by (title = 'History') + (body_text_1 = 'History') + (body_text_2 = 'History') + (body_text_34 = 'History') desc
推荐阅读
- java - 使用 Bitbucket 管道更新 AWS Java Lambda 函数时出错 - java.lang.ClassNotFoundException
- javascript - How can I find all of rows which are selected by CSS in JS?
- javascript - How do I calculate two text boxes and display the answer in another?
- php - highlight last 3 number in the string
- drupal - 新用户注册时分配默认角色 - drupal 8
- c - C 编程函数调用以返回值
- sql - How to select hierarchical records from two tables using join
- reactjs - 向 React Typescript 高阶组件添加属性,包括实现
- java - How to enable auto-complete (intellisense) in Eclipse IDE for Java
- angular - How to access inputs from Textfields in NativeScript and save them to variables like you can with document.getElementByID