仅当一个以上的组连接到组时

2024-05-29 06:22:34 发布

您现在位置:Python中文网/ 问答频道 /正文

我只想在SQLite中对有多行要连接的记录执行组concat。似乎您可以事先这样做(先用一个组计算记录数,然后在继续分组\u-concat之前删除那些单例行);之后(完成group\u-concat,然后删除没有连接任何内容的行);或者甚至可能在?在

我的问题是:SQLite实现这一目标的最快方式是什么?在

我在Python中使用APSW编写了一个“after”示例,但对此并不满意:

#set up a table with data
c.execute("create table foo(x,y)")
def getvals():
    a = [1, 1, 2, 3, 3]
    b = ['a','b','c','d','e']
    for i in range(5):
        yield a[i],b[i]
c.executemany("insert into foo values(?,?)",getvals())
c.execute('''create table fooc(a,b);
    insert into fooc(a,b) select x, group_concat(y) from foo group by x''')
c.execute('select * from fooc')
c.fetchall()  ## reports three records
c.execute("select * from fooc where b like '%,%'")
c.fetchall() ## reports two records .. what I want

它看起来很疯狂(而且很慢?)用LIKE来满足这种需要。在


Tags: fromexecutesqlitefoocreate记录tablegroup

热门问题