有更好的方法吗?

发布于 2024-10-25 08:54:40 字数 844 浏览 4 评论 0原文

我有一个带有“cellid”“date”(日期时间)和“block”(真实)列的表。

我正在尝试查找所有具有 block > 的 id。过去 3 天为 1。

我目前正在这样做:

cells = npar.db.execute("SELECT cellid FROM data WHERE block > 1 AND date=?", (files[0][1],)).fetchall()
cells1 = npar.db.execute("SELECT cellid FROM data WHERE block >1 AND date = ?", (files[1][1],)).fetchall()
self.common(cells,cells1)
cells1 = npar.db.execute("SELECT cellid FROM data WHERE block >1 AND date = ?", (files[2][1],)).fetchall()
self.common(cells,cells1)

print len(cells)
def common(self,a,b):
    for item in a:
            if item not in b:
                a.remove(item)

b = npar.db.execute("SELECT cellid FROM data WHERE block > 1 AND date >= ? GROUP BY cellid HAVING COUNT(cellid) = 3", (files[2][1],)).fetchall()
        print len(b)

len(b) 不等于 len(cells)

I'm have a table with 'cellid' 'date'(datetime) and 'block'(real) columns.

I'm trying to find all the id's which had block > 1 for the last 3 days.

I'm currently doing it like this:

cells = npar.db.execute("SELECT cellid FROM data WHERE block > 1 AND date=?", (files[0][1],)).fetchall()
cells1 = npar.db.execute("SELECT cellid FROM data WHERE block >1 AND date = ?", (files[1][1],)).fetchall()
self.common(cells,cells1)
cells1 = npar.db.execute("SELECT cellid FROM data WHERE block >1 AND date = ?", (files[2][1],)).fetchall()
self.common(cells,cells1)

print len(cells)
def common(self,a,b):
    for item in a:
            if item not in b:
                a.remove(item)

b = npar.db.execute("SELECT cellid FROM data WHERE block > 1 AND date >= ? GROUP BY cellid HAVING COUNT(cellid) = 3", (files[2][1],)).fetchall()
        print len(b)

len(b) is not equal to len(cells)

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

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

发布评论

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

评论(1

我不咬妳我踢妳 2024-11-01 08:54:40

“过去 3 天”?那么以下可以工作吗?

cells = npar.db.execute("SELECT cellid FROM data "
                        "WHERE block > 1 "
                        "AND date >= ? "
                        "GROUP BY cellid "
                        "HAVING COUNT(*) = 3", (files[0][1],)).fetchall()

"for the last 3 days"? So the following could work?

cells = npar.db.execute("SELECT cellid FROM data "
                        "WHERE block > 1 "
                        "AND date >= ? "
                        "GROUP BY cellid "
                        "HAVING COUNT(*) = 3", (files[0][1],)).fetchall()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文