标签:sel iter class 相同 HERE not union ber monthly
query = Facility.select() 等价于SQL SELECT * FROM facilities
Facility.select(Facility.name, Facility.membercost) 等价于 SELECT name, membercost FROM facilities;
Facility.select().where(Facility.membercost > 0) 等价于 SELECT * FROM facilities WHERE membercost > 0
Facility.select().where(Facility.name.contains(‘tennis‘)) 等价 SELECT * FROM facilities WHERE name ILIKE ‘%tennis%‘;
或者 Facility.select().where(Facility.name ** ‘%tennis%‘)
query = Facility.select().where(Facility.facid.in_([1, 5])) in操作
SELECT name,
CASE WHEN monthlymaintenance > 100 THEN ‘expensive‘ ELSE ‘cheap‘ END
FROM facilities;
对应ORM语句
cost = Case(None, [(Facility.monthlymaintenance > 100, ‘expensive‘)], ‘cheap‘)
query = Facility.select(Facility.name, cost.alias(‘cost‘))
比较日期
SELECT memid, surname, firstname, joindate FROM members
WHERE joindate >= ‘2012-09-01‘;
Member.select(Member.memid, Member.surname, Member.firstname, Member.joindate).where(Member.joindate >= datetime.date(2012, 9, 1))
SELECT DISTINCT surname FROM members ORDER BY surname LIMIT 10;
Member.select(Member.surname).order_by(Member.surname).limit(10).distinct()
UNION 操作 把查询到的数据 合并 到一起 前提:列数相同
SELECT surname FROM members UNION SELECT name FROM facilities;
lhs = Member.select(Member.surname)
rhs = Facility.select(Facility.name)
query = lhs | rhs
|
代表 UNION 相同的只显示一次
+
代表 UNION ALL 都显示
&
代表 INTERSECT 只显示相同的
-
代表 EXCEPT
SELECT MAX(join_date) FROM members;
query = Member.select(fn.MAX(Member.joindate))
标签:sel iter class 相同 HERE not union ber monthly
原文地址:https://www.cnblogs.com/escapist/p/10754197.html