有更好的方法吗?
我有一个带有“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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
“过去 3 天”?那么以下可以工作吗?
"for the last 3 days"? So the following could work?