sql语句
Posted 行走在云端
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql语句相关的知识,希望对你有一定的参考价值。
# 取单价为最近时间的单价
sql="select price_unit from sale_price_list where partner_id=%d and product_id=%d order by write_date desc limit 1"%(partner_id,product_id)
cr.execute(sql)
#查询出销售订单的源单据是本外部订单的所有单据
sql2=" UPDATE stock_picking SET state=‘cancel‘ where state=‘draft‘ and order_name=‘%s‘"%(str(a))
cr.execute(sql2)
select t0.partner_id id,t0.partner_id,sum(t0.subtotal) alltotal,coalesce(t2.subtotal,0) dlvtotal,intotal,coalesce(t2.subtotal,0)-coalesce(intotal) uintotal from sale_origin t0
left join (select partner_id,coalesce(sum(type*pay_total),0) intotal from partner_for_payment group by partner_id) t1 on t0.partner_id=t1.partner_id
left join ( select t5.partner_id,sum(t4.total) as subtotal from (
select t0.product_id,t1.order_name,sum((COALESCE(case when t0.location_id=get_warehouse_id(‘成品仓‘) then product_qty else -1*product_qty end,0))*t0.pprice) as total
from stock_move t0
left join stock_picking t1 on t0.picking_id=t1.id
where t0.state=‘done‘
and ((t0.location_id=get_warehouse_id(‘成品仓‘) and t0.location_dest_id=get_warehouse_id(‘Customers‘))
or (t0.location_id=get_warehouse_id(‘Customers‘) and t0.location_dest_id=get_warehouse_id(‘成品仓‘)))
group by t0.product_id,t1.order_name,t0.pprice
) as t4
LEFT JOIN sale_origin t5 on t5.name=t4.order_name
GROUP BY t5.partner_id )t2 on t2.partner_id=t0.partner_id
where t0.state=‘confirm‘ group by t0.partner_id,t2.subtotal,t1.intotal
以上是关于sql语句的主要内容,如果未能解决你的问题,请参考以下文章