mysqlindex函数⽤法_mysql的indexof函数⽤法说明如下所⽰:
locate(substr,str)
返回⼦串substr在字符串str第⼀个出现的位置,如果substr不是在str⾥⾯,返回0.
mysql> select locate('bar', 'foobarbar'); -> 4 mysql> select locate('xbar', 'foobar'); -> 0
补充:mysql中类似indexof的⽅法locate()
locate(substr, str), locate(substr, str, pos)
第⼀个语法返回substr在字符串str的第⼀个出现的位置。
第⼆个语法返回字符串substr在字符串str,从pos处开始的第⼀次出现的位置。如果substr不在str中,则返回值为0
表格index函数怎么用问题:
有多个科⽬,⼀个科⽬下多个多选题,每个题四种答案(abcd),统计每个科⽬的每道题选择abcd的个数
select
sum(
case
when (locate('a', 选项名) > 0) then
1
else
end
) as a,
sum(
case
when (locate('b', 选项名) > 0) then
1
else
end
) as b,
sum(
case
when (locate('c', 选项名) > 0) then
1
else
end
) as c,
sum(
case
when (locate('d', 选项名) > 0) then
1
else
end
) as d
from
表名
以上为个⼈经验,希望能给⼤家⼀个参考,也希望⼤家多多⽀持萬仟⽹。如有错误或未考虑完全的地⽅,望不吝赐教。如您对本⽂有疑问或者有任何想说的,请点击进⾏留⾔回复,万千⽹友为您解惑!