SQLite:选择连续行中不带小数的字母数字条目

发布于 2024-12-12 14:36:36 字数 371 浏览 5 评论 0原文

我有一个 SQLite DB,其中包含一系列字母数字代码和描述。这两个字段都是文本。编码格式是单个字母字符后跟 2 位数字值 - 这是父类别。许多父类别都有子项目 - 其中代码由小数点扩展,然后是字母数字值...因此:

A01 是父类别

A01.10 是子项目

我想SELECT没有子项的代码...此表中有 80000 个条目,因此手动遍历它并不理想;)

因此,包含标准是代码 [an][n][n] 存在且[an][n][n].% 不存在...任何想法/指导表示赞赏:)

TABLE 称为“Terms”,Code 字段想象地称为 Code TIA

I have an SQLite DB comprising of a series of alphanumerical codes and descriptions. Both fields are TEXT. The coding format is a single alphabetical character followed by 2 digit numerical value - this is the parent category. Many parent categories have sub-items - where the code is extended by a decimal and then an alphanumerical value... so:

A01 is a parent category

A01.10 is a subitem

I would like to SELECT the codes where there are no sub-items... There are 80000 entries in this table, so going through it manually isn't ideal ;)

So, the inclusion criteria are where code [an][n][n] exists AND [an][n][n].% doesn't exist... Any ideas / guideance appreciated :)

The TABLE is called 'Terms' and the Code field is imaginatively called Code

TIA

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

惯饮孤独 2024-12-19 14:36:36

字符串处理并不完全是 SQLite 的强项,但我认为你可以用一种稍微迂回的方式来完成它:

select *
from terms
where code not like '%.%'
  and code not in (
    select rtrim(rtrim(code, '1234567890'), '.')
    from terms
    where code like '%.%'
);

这个想法是首先找出哪些代码有子项,然后排除它们。

给定这些数据:

id | code
 1 | a01
 2 | a02
 3 | a03
 4 | a03.1
 5 | a03.2
 6 | a01.1

然后该查询会给出以下结果:

id | code
2  | a02

String processing isn't exactly SQLite's strong point but I think you get it done in a slightly round about way:

select *
from terms
where code not like '%.%'
  and code not in (
    select rtrim(rtrim(code, '1234567890'), '.')
    from terms
    where code like '%.%'
);

The idea is to first figure out which codes have sub-items and then exclude them.

Given this data:

id | code
 1 | a01
 2 | a02
 3 | a03
 4 | a03.1
 5 | a03.2
 6 | a01.1

Then that query gives you this:

id | code
2  | a02
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文