mysql 优化

select order_id,order_sn from (select concat('@@',order_sn) as x ,order_sn,order_id from ecs_order_info where 1 = 1 having x like '@@%0002%') as t;

SELECT m.uid,m.realname,IFNULL(r1.paynum,0) as paynum,IFNULL(rr.nopaynum,0) as nopaynum FROM `ims_mc_members` as m
 LEFT JOIN (select uid,count(uid) as nopaynum from ims_fx_activity_records as r where `status`=0 and merchantid='293' GROUP BY uid) as rr on rr.uid=m.uid 
 LEFT JOIN (select uid,count(uid) as paynum from ims_fx_activity_records  as r  where `status`>0 and merchantid='293' GROUP BY uid) as r1 on r1.uid=m.uid 
 where m.merchant_id='292' ORDER BY r1.paynum desc,rr.nopaynum desc  ;

//查询统计多表 去重 分组 排序

  SELECT `order_sn` FROM `ecs_order_info` where concat('@',`order_sn`)  like '@%11101%';

  SELECT `subject` FROM `taobao_product0` where `subject`  like '_%1114%';

字段值前面加前缀 比如 @

SELECT `subject` FROM `taobao_product0` where `subject`  like '@%1114%';

用到索引 速度很快

mysql 按时间排序

ORDER BY UNIX_TIMESTAMP(modifyTime) desc  代替 ORDER BY modifyTime desc 效率提高

[SQL]  SELECT * FROM `taoyang1`.`ecs_order_info` WHERE order_sn in ('171497');
受影响的行: 0
时间: 0.016ms

[SQL] 
 SELECT * FROM `taoyang1`.`ecs_order_info` WHERE order_sn in (171497);
受影响的行: 0
时间: 7.906ms

多个字段 联合搜索

$where=" and CONCAT(`mall_name`,userName,`userId`) LIKE '%$kw%'";

分类匹配 搜索匹配 最佳匹配类目

SELECT * from pdd_cats where is_enabled=1 and `level` in(3,4) and ((cat_name_all REGEXP '^汽车' and cat_name_all REGEXP '汽车|零部件|养护|美容|维|保|汽车|美容|漆|膜|蜡|补|漆|笔|五|菱|荣光|6450pf6407b|车|漆|划痕|修复|亮|米黄|雷|迅|灰|宝石蓝|银色|自|喷漆' ) or cat_name REGEXP '^补漆笔') ORDER BY LOCATE('补漆笔',cat_name) DESC, `level` desc ;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值