今天在写列表条件查询时,发现加上条件以后,结果不是很理想,由于有用到instr 来进行模糊查询,因此觉得是instr和or 使用时会有前后执行顺序。查找了资料后发现是and 与or 一块儿使用时,须要注意到的问题
如下是个人查询语句html
SELECT product_id ,product_name,create_uid ,emai FROM product p INNER JOIN user_product up ON p.product_id = up.product_id LEFT JOIN istats_product_total spt ON p.product_id = spt.product_id LEFT JOIN `user` u ON p.`create_uid`=u.id WHERE p.server_type=0 AND up.`user_type` =1 AND up.uid =85 OR (up.uid IN (SELECT id FROM `user` u WHERE u.parent_uid =85 AND u.`account_type` IS NULL) AND up.`user_type` =2) AND (INSTR(u.email, 'xxxxx@aliyun.com') ) GROUP BY p.product_id ORDER BY p.create_time DESC
能够看到,除了模糊查询,固定的条件已经用到了and 和or 。我但愿获得的是条件为 uid =59,user_type =1 或者 parent_uid=59 ,user_type =2 这样的结果 ,而且模糊查询条件时也能过滤一部分结果。但其实查询结果没有问题,加了模糊查询以后就发现没什么用
参考了下这个https://www.cnblogs.com/muzixiaodan/p/5632606.html
修改成,就能够了mysql