select MAX(update_datetime) as update_datetime,commodity_code, commodity_name,
commodity_num, commodity_specifications,commodity_pingyin, commodity_type,
commodity_main, commodity_in, commodity_out, commodity_brand from commodity
where shopId is not null and update_datetime is not null and
CHAR_LENGTH(commodity_code) >= 12 and CHAR_LENGTH(commodity_code) < 50 and
commodity_name NOT REGEXP '无码商品|测试|次卡|年卡|季卡|月卡|券|现金' and
commodity_code REGEXP '^[0-9a-zA-Z]' and (
commodity_in REGEXP '^(([1-9]{1}[0-9]*)|([0]{1}))([.]([0-9]+))?$' OR
LENGTH(trim(commodity_in)) < 1) and (
commodity_out REGEXP '^(([1-9]{1}[0-9]*)|([0]{1}))([.]([0-9]+))?$' OR
LENGTH(trim(commodity_out)) < 1) and NOT
REPLACE(commodity_code,SUBSTR(commodity_code,1,1),"") = "" GROUP BY commodity_code
从各方面优化这个sql查询,mysql数据库,查询数据量100w以内目前查询需要8秒
不知道你这个问题是否已经解决, 如果还没有解决的话: