sqlalchemy 统计记录条数(distinct)

from sqlalchemy import func

# count User records, without

# using a subquery.

session.query(func.count(User.id))

# return count of user "id" grouped

# by "name"

session.query(func.count(User.id)).\

group_by(User.name)

from sqlalchemy import distinct

# count distinct "name" values

session.query(func.count(distinct(User.name)))

你可能感兴趣的:(sqlalchemy 统计记录条数(distinct))