python中的 sql语句用法
函数中应用sql语句
def _get_cust_number(self,cr,uid,ids,field_name,args,context=None):
res={}
for order in self.browse(cr, uid, ids, context=context):
#获取单据信息
aa=order.origin
if aa:
sql="select t1.cust_numr_no from stock_fah t0 left join sale_orde t1 on t0.origin=t1.name where t0.origin='%s'"%(aa)
cr.execute(sql)
dict4=cr.dictfetchall()
if dict4:
dd=dict4[0]['cust_numr_no']
res[order.id]=dd
else:
res[order.id]=''
else:
res[order.id]=''
return res
或者着一种
函数中另外一种写法cr.execute
cr.execute('''select ref_line_id,nolqty from( select ref_line_id,sum(COALESCE(case when t0.location_id=get_warehouse_id('成仓') then product_qty when t0.location_id=get_warehouse_id('原仓') then product_qty else -1*product_qty end,0) ) dlvqty from
stock_ynum t0 left join stock_fah 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('成仓')))
or ((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,ref_num,ref_line_id)t where ref_line_id in %s''',(tuple(ids),))
jhqty = dict(cr.fetchall())
或者创建views
初始化执行的函数:创建一个视图,用sql语句 ,紫色为sql语句 def init(self,cr):
tools.sql.drop_view_if_exists(cr, 'cust_cp_info_report')
cr.execute("""
create or replace view cust_product_info_report as (
select t0.id,t0.hpartner_id as hpartner_id, t0.khwl_code as khwl_code,t1.product_mp_id as productn,
t3.pname,t3.mmar,t3.spec,
t4.id as name_uom, t5.price as custo_price,t0.product_meno as product_meno ,t0.meno as meno,t5.date_from,t5.date_to
from product_custo_info t0
LEFT JOIN product_order t1 on t0.product_tmpl_id=t1.product_tmpl_id
LEFT JOIN product_model t3 on t3.id=t1.product_tmpl_id
LEFT JOIN ke_partner t2 on t2.id=t0.hpartner_id
LEFT JOIN product_dan t4 on t3.uom_id=t4.id
left join partner_cp_price t5 on t5.ppp_line_id=t0.id
where (now()>=t5.date_from and now()<=t5.date_to) or (t5.date_from is null and t5.date_to is null ) or
(t5.date_from is null and (now()<=t5.date_to)) or (t5.date_to is null and (now()>=t5.date_from)) )
""")
python中的 sql语句用法的更多相关文章
- Mybatis中动态SQL语句中的parameterType不同数据类型的用法
Mybatis中动态SQL语句中的parameterType不同数据类型的用法1. 简单数据类型, 此时#{id,jdbcType=INTEGER}中id可以取任意名字如#{a,jdbcType ...
- 详解Python中的循环语句的用法
一.简介 Python的条件和循环语句,决定了程序的控制流程,体现结构的多样性.须重要理解,if.while.for以及与它们相搭配的 else. elif.break.continue和pass语句 ...
- Python中防止sql注入的方法详解
SQL注入是比较常见的网络攻击方式之一,它不是利用操作系统的BUG来实现攻击,而是针对程序员编程时的疏忽,通过SQL语句,实现无帐号登录,甚至篡改数据库.下面这篇文章主要给大家介绍了关于Python中 ...
- 在mybatis中写sql语句的一些体会
本文会使用一个案例,就mybatis的一些基础语法进行讲解.案例中使用到的数据库表和对象如下: article表:这个表存放的是文章的基础信息 -- ------------------------- ...
- 在Excel中使用SQL语句查询和筛选
本文转自:http://blog.sina.com.cn/s/blog_5fc375650102e1g5.html 今天在微博上看到@数据分析精选 分享的一篇文章,是关于<在Excel中使用SQ ...
- EF中执行sql语句,以及事务
EF to sql string sql = "select T_Task.BSID,T_Task.CloseDate,T_Task.CompleteDate,T_Task.CloseUse ...
- [转]在EntityFramework6中执行SQL语句
本文转自:http://www.cnblogs.com/wujingtao/p/5412329.html 在上一节中我介绍了如何使用EF6对数据库实现CRDU以及事务,我们没有写一句SQL就完成了所有 ...
- 在EntityFramework6中执行SQL语句
在EntityFramework6中执行SQL语句 在上一节中我介绍了如何使用EF6对数据库实现CRDU以及事务,我们没有写一句SQL就完成了所有操作.这一节我来介绍一下如何使用在EF6中执行SQL语 ...
- 在phpmyadmin中执行sql语句出现的错误:Unknown storage engine 'InnoDB'
在phpmyadmin中执行sql语句出现的错误:Unknown storage engine 'InnoDB' 解决方法:解决方法: 1.关闭MySQL数据库 2 ...
随机推荐
- 前端打包文件在 nginx 上 403 的解决办法
遇到的问题表现出来就是如题所述,因此作为题目. 我们知道,前端有很多方便的构建和打包工具,如 webpack 等,通常我们会把前端文件打包到dist目录下,部署到服务器上,如 nginx 等. 这次遇 ...
- BeanFactory和ApplicationContext的比较
1.BeanFactory实例化后,不会马上实例化Bean:ApplicationContext在实例化后紧跟着就会实例化Bean 2.ApplicationContext还实现了ResourceLo ...
- Android ListView在增加HeaderView之后使用getLocationInWindow和getLocationOnScreen获得值不正确的解决方法
近日遇到一个很恶心的问题,把解决方法放到空间里来分享给大家: 问题发生的条件: 1)ListView 控件中使用addHeaderView,为其添加了一个header view.(基本常识:heade ...
- server 2008 软阵列
RAID0:没有容错功能,等.两块以上的硬盘.RAID1:不能提高速度,有容错功能,等.注意:只能用两块硬盘,有的地方说可以用两块以上,你不信试试三块硬盘,肯定添加不了,但是可以做raid10.RAI ...
- Hadoop2.7.6_03_HDFS原理
1. HDFS前言 l 设计思想 分而治之:将大文件.大批量文件,分布式存放在大量服务器上,以便于采取分而治之的方式对海量数据进行运算分析: l 在大数据系统中作用: 为各类分布式运算框架(如:m ...
- VMware安装CentOS6
1. 搭建虚拟化环境常见故障讲解 2. 安装CentOS Linux系统 ……………… PS:运维老鸟教你安装centos6.5如何选择安装包 3. 远程连接LInux ip配置 注意:不用做任何修改 ...
- nginx配置静态资源访问
本篇配置使用场景:本地通过浏览器访问linux上某个文件夹下的文件: 1.安装jdk及nginx步骤省略 2.进入正题 (1) 查看nginx安装路径:[root@localhost conf]# w ...
- Mac显示器不亮
上班的时候mac连接上显示器,但是显示器并没有亮,于是乎各种插拔ing...偶尔一两次还可以接受,但是天天这样小身板招架不住呀,于是乎终于找到一个可以让显示器快速亮起的方法,遂赶紧分享给各位小火鸡~ ...
- android Application Component研究之Activity(一)
http://blog.csdn.net/windskier/article/details/7096521 终于下定决心写写ActivityManagerService的源码分析的文章了,Activ ...
- 编译apache报APR not found
系统环境: [vagrant@rs-2 download]$ cat /etc/redhat-release CentOS release 5.6 (Final) [vagrant@rs-2 dow ...