MySQL LIKE与范围不起作用
作者:互联网
我有一个数据库表mytable,其列名为Varchar格式,列日期为Datetime值.我想用按日期分组的某些参数来计算名称.这是我做的:
SELECT
CAST(t.date AS DATE) AS 'date',
COUNT(*) AS total,
SUM(LENGTH(LTRIM(RTRIM(t.name))) > 4
AND (LOWER(t.name) LIKE '%[a-z]%')) AS 'n'
FROM
mytable t
GROUP BY
CAST(t.date AS DATE)
似乎这里的范围语法有问题,如果我只是做’a%’,它会正确计算所有以’a’开头的字段.但是,上面的查询为n返回0,尽管应该计算包含至少一个字母的所有字段.
解决方法:
你写:
It seems that there’s something wrong with range syntax here
的确如此. MySQL的LIKE运算符(和SQL一般)does not support range notation,只是简单的通配符.
尝试MySQL的非标准RLIKE(a.k.a.REGEXP),以获得更全面的模式匹配.
标签:mysql,sql-like 来源: https://codeday.me/bug/20190928/1826012.html