-1

如果我搜索“销售订单”,它会在结果中获取“销售订单”和“销售订单” 它也用“s”获取结果。

但是,如果我搜索“销售订单”,它只会获取“销售订单”,但我希望“销售订单”也会获取。

我正在使用 php mysql 查询。

SELECT DISTINCT * FROM wp_posts as p 
    inner join wp_postmeta as pm on pm.post_id = p.ID 
    where (p.post_type = 'abc' or p.post_type = 'xyz') 
    and p.post_title LIKE '%sales order%' 
    or (pm.meta_key = 'xyzkeyword' and pm.meta_value LIKE '%sales order%') 
    GROUP by p.ID 
    ORDER BY p.id DESC
4

4 回答 4

1

试试这个没有“%”

p.post_title LIKE 'sales order'
于 2018-02-15T07:04:50.993 回答
0

我不太确定这个查询,但你可以检查为

SELECT DISTINCT * FROM wp_posts as p 
inner join wp_postmeta as pm on pm.post_id = p.ID 
where (p.post_type = 'abc' or p.post_type = 'xyz') 
and p.post_title LIKE '%sales%' AND  p.post_title LIKE '%order%'
or (pm.meta_key = 'xyzkeyword' and pm.meta_value LIKE '%sales order%') 
GROUP by p.ID 
ORDER BY p.id DESC

或者

SELECT DISTINCT * FROM wp_posts as p 
inner join wp_postmeta as pm on pm.post_id = p.ID 
where (p.post_type = 'abc' or p.post_type = 'xyz') 
and p.post_title LIKE '%sales%order%'
or (pm.meta_key = 'xyzkeyword' and pm.meta_value LIKE '%sales order%') 
GROUP by p.ID 
ORDER BY p.id DESC
于 2018-02-15T07:21:26.387 回答
0

你也可以这样尝试

and (p.post_title LIKE '%sales order%'  OR p.post_title LIKE '%sales orders%' )

我希望这能解决你的问题。

于 2018-02-15T07:17:59.390 回答
0
use MySQL Full text search,check if FULLTEXT indexes are there

SELECT DISTINCT * FROM wp_posts as p 
    inner join wp_postmeta as pm on pm.post_id = p.ID 
    where (p.post_type = 'abc' or p.post_type = 'xyz')
    match (p.post_title) against ('sales order')
    or (pm.meta_key = 'xyzkeyword' and pm.meta_value LIKE '%sales order%') 
    GROUP by p.ID 
    ORDER BY p.id DESC
于 2018-02-15T07:40:02.597 回答