You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

SQLite中如何用Substr提取竖线后的时段字符串?

解决SQLite提取竖线后字符串的问题

SQLite的substr()函数语法是substr(字符串, 起始位置[, 长度]),你直接传入'|'作为第二个参数会被转换为数值0,因此会返回整个原字符串,这就是问题的根源。

要提取|之后的时段部分,需要先通过instr()函数定位竖线的位置,再从该位置的下一位开始截取:

select count(distinct b.id), 
       h.business_id, 
       substr(h.hours, instr(h.hours, '|') + 1) as time_range,
       b.stars
-- 请补充表关联条件,例如:from hours_table h join business_table b on h.business_id = b.id
-- 按需添加where过滤条件

instr(h.hours, '|')会返回|在字符串中的索引位置(从1开始计数),加1后就是时段内容的起始位置,这样substr就能精准截取到18:00-2:00这类目标内容。

内容的提问来源于stack exchange,提问作者edward_apc

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.14 16:43:12