我假设您基本上想要每个线程的最后帖子的 25%,以后的操作取决于您。
如果我是对的,那么这段代码应该适合你(为 MS-SQL 编写,应该很容易移植到 SQLite):
CREATE TABLE posts (
post_id INT,
thread_id INT
)
INSERT INTO posts(post_id, thread_id) VALUES (1, 1)
INSERT INTO posts(post_id, thread_id) VALUES (2, 2)
INSERT INTO posts(post_id, thread_id) VALUES (3, 2)
INSERT INTO posts(post_id, thread_id) VALUES (4, 3)
INSERT INTO posts(post_id, thread_id) VALUES (5, 3)
INSERT INTO posts(post_id, thread_id) VALUES (6, 3)
INSERT INTO posts(post_id, thread_id) VALUES (7, 3)
INSERT INTO posts(post_id, thread_id) VALUES (8, 3)
INSERT INTO posts(post_id, thread_id) VALUES (9, 3)
INSERT INTO posts(post_id, thread_id) VALUES (10, 3)
INSERT INTO posts(post_id, thread_id) VALUES (11, 3)
SELECT src.*
FROM (
SELECT post_number = (
SELECT 1 + COUNT(*)
FROM posts pp
WHERE p.post_id > pp.post_id
AND p.thread_id = pp.thread_id
),
post_id,
thread_id
FROM posts p
) src
JOIN (
SELECT thread_id, cnt = COUNT(*)
FROM posts
GROUP BY thread_id
) counts
ON src.thread_id = counts.thread_id
WHERE (CONVERT(FLOAT, src.post_number) / CONVERT(FLOAT, counts.cnt)) >= 0.75
请注意,它不是高性能查询,主要是由于子查询获取 post_number。对于支持它的 DBMS,它可以用 OVER 子句以更好的方式编写。