在python sqlalchemy中子查询的使用
来源:互联网 发布:java封装 编辑:程序博客网 时间:2024/05/17 01:00
query = select([machine_products_table.c.id, /
machine_products_table.c.machine_id.label("kiosk"), /
machine_products_table.c.sale_price.label("sale_price"), /
machine_products_table.c.quantity.label("quantity"), /
select([func.min(machine_stock_events_table.c.action_time)], /
and_(machine_stock_events_table.c.machine_id==machine_products_table.c.machine_id, /
machine_stock_events_table.c.product_id==productId)).as_scalar().label("load_days"), /
select([func.max(machine_transactions_table.c.trs_time)], /
and_(machine_transactions_table.c.machine_id==machine_products_table.c.machine_id, /
machine_transactions_table.c.product_id==productId, /
machine_transactions_table.c.state == "closed")).as_scalar().label("no_transaction_days")/
], /
and_(machine_products_table.c.machine_id.in_(select([machines_table.c.machine_id], /
machines_table.c.client_id==clientId).as_scalar()), /
machine_products_table.c.product_id==productId, /
machine_products_table.c.quantity != 0))
if sortKey:
if str(sortOrder).lower() == "desc":
query = query.order_by(sortKey.desc())
else:
query = query.order_by(sortKey)
if limit:
query = query.limit(limit)
if offset:
query = query.offset(offset)
tmp = meta.Session.execute(query).fetchall()
result = []
for t in tmp:
load_days = '--'
no_transaction_days = '--'
if t[4]:
load_days = getDaySpan(str(t[4]),getCurTime())
if t[5]:
no_transaction_days = getDaySpan(str(t[5]),getCurTime())
result.append((t[0], t[1], t[2], t[3], load_days, no_transaction_days))
- 在python sqlalchemy中子查询的使用
- Python-SQLAlchemy的使用
- Python使用SQLAlchemy查询所有表名
- Oracle中子查询的使用实例
- Hibernate中子查询(subselect)的使用
- mysql中子查询和连接的使用
- 【Python】SQLALchemy-查询篇
- python sqlalchemy模糊查询
- python sqlalchemy 连接查询
- Python SQLalchemy ORM的使用(一)
- 关于python使用sqlalchemy
- python SQLAlchemy 使用经验
- python使用SQLAlchemy
- python之sqlalchemy使用
- sqlalchemy的嵌套查询
- python 的 SQLAlchemy操作
- python sqlalchemy的应用
- python的sqlalchemy模块
- 设计模式的六大原则
- Hibernate之session
- 影响一个UIView是否能正常显示的几个因素
- 如何完全杀掉带锁的进程并释放资源
- Android学习笔记(十三)-使用Socket进行大文件断点上传续传
- 在python sqlalchemy中子查询的使用
- java学习小笔记(二.i/o)
- 转 -- 基于DDS的Oracle灾备方案
- [Erlang 0019]Redis协议解读与实现(.Net & Erlang)
- 小探移动设备上的语音识别
- socket异步操作
- linux jdk环境安装整理
- java学习小笔记(三.socket通信)
- Iphone文本切页代码