嘿,有些人可以告诉我sqlite3中的查询,只有在我的数据库中存在多次才能用于选择条目
答案 0 :(得分:1)
答案 1 :(得分:1)
Select DISTINCT <Column> FROM <Table> order by <Column>
答案 2 :(得分:0)
您还可以使用GROUP BY
:
SELECT <Column>
FROM <Table>
GROUP BY <Column>
E.g:
>>> import sqlite3
>>> conn = sqlite3.connect(':memory:')
>>> c = conn.cursor()
>>> c.execute("CREATE TABLE test (col text);")
<sqlite3.Cursor object at 0x7f9ba3ec3c90>
>>> c.execute("INSERT INTO test VALUES ('distinct');")
<sqlite3.Cursor object at 0x7f9ba3ec3c90>
>>> c.execute("INSERT INTO test VALUES ('distinct');")
<sqlite3.Cursor object at 0x7f9ba3ec3c90>
>>> c.execute("SELECT col FROM test;").fetchall() # three results
[(u'distinct',), (u'distinct',), (u'distinct',)]
>>> c.execute("SELECT col FROM test GROUP BY col;").fetchall() # one result
[(u'distinct',)]