gpt4 book ai didi

php - 根据搜索结果查询订单结果

转载 作者:行者123 更新时间:2023-11-30 00:06:51 24 4
gpt4 key购买 nike

我正在创建一个搜索函数并采用输入参数并使用以下查询查询我的数据库:

select * from people where title like '{param}%' or title like '%{param}%';

我的问题是,这会按预期返回所有记录,但我想对结果进行排序,以便 where 语句“title like '{param}%”' 的结果首先返回,然后返回以下 where 语句。

有什么办法可以做到这一点吗?

最佳答案

尝试一下:

  select * from people where title like '{param}%' or title like '%{param}%'
ORDER BY CASE when title like '{param}%' then 0
when title like '%{param}%' then 1 end asc

关于php - 根据搜索结果查询订单结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24466459/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com