我有下表
CREATE TABLE actions (id INTEGER PRIMARY KEY, key1 NUMERIC, key2 NUMERIC);
Run Code Online (Sandbox Code Playgroud)
我甚至不确定如何解释这个,所以我认为最好我举个例子:
id key1 key2
1 1 1
2 1 2
3 1 1
4 2 1
5 2 3
Run Code Online (Sandbox Code Playgroud)
输出这样的东西:
key1 key2 count(id)
1 1 2
1 2 1
2 1 1
2 3 1
Run Code Online (Sandbox Code Playgroud)
我试过这样的东西,但它不起作用,因为我需要key1字段不是唯一的:
Select key1,key2,count(id) from actions group by key2, order by key1
Run Code Online (Sandbox Code Playgroud)
非常感谢
我在使用MySQLdb API时遇到了我认为是内存泄漏的问题
Line # Mem usage Increment Line Contents
================================================
6 @profile
7 10.102 MB 0.000 MB def main():
8 10.105 MB 0.004 MB connection = MySQLdb.connect(host="localhost", db="mydb",
9 11.285 MB 1.180 MB user="notroot", passwd="Admin123", use_unicode=True)
10 11.285 MB 0.000 MB cursor = connection.cursor(cursorclass=MySQLdb.cursors.SSCursor)
11
12 11.289 MB 0.004 MB cursor.execute("select * from a big table;")
13
14 254.078 MB 242.789 MB results = [result for result in cursor]
15 251.672 MB -2.406 MB del results
16 251.672 MB 0.000 …Run Code Online (Sandbox Code Playgroud)