选择逗号分隔列表项的数量
我有一列包含逗号分隔值,我需要选择包含 13 个逗号的所有行。它们分隔数字,因此我无需担心任何包含逗号的字符串。我该怎么做?
I have a column that has comma seperated values and I need to select all rows that have 13 commas. They seperate numbers so I don't need to worry about any strings that contain commas. How would I do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
为了
更好地利用索引,您应该寻求标准化您的表
alternative to like (I do not like the
like
, and the above will fail if contains 14 commas or more)for better utilize the index, you should seek to normalize your table
如果您使用 PostgreSQL,您还可以使用正则表达式。
但是,更好的问题可能是为什么只有一个包含逗号分隔值的列而不是多个列。
If you're using PostgreSQL, you could also use regular expressions.
However, a better question might be why you have a single column with comma-separated values instead of multiple columns.
如果将包含 14 个逗号的字符串算作包含 13 个逗号,那么这将起作用:
%
匹配任何字符串(包括零长度)。If you count a string with 14 commas as having 13 commas, then this will work:
%
matches any string (including zero length).在 PostgreSQL 中你可以这样做:
In PostgreSQL you can do: