当前位置:Gxlcms > 数据库问题 > sql语句

sql语句

时间:2021-07-01 10:21:17 帮助过:23人阅读

取单价为最近时间的单价
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语句

标签:join   name   int   bsp   sub   ice   cat   from   cas   

人气教程排行