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 ...
随机推荐
- 【工具相关】Web-XAMPP的安装
一,在查度中搜索XAMPP,会如下所示,下载软件 ,依次进行安装. 二,安装完成之后,会生成如下的图标. 三,打开上图的图标,如下图所示. 四,选择Apache Web Server---->S ...
- 从零开始学习html(二)认识标签(第一部分)——上
一.语义化,让你的网页更好的被搜索引擎理 学习html标签过程中,主要注意两个方面的学习:标签的用途.标签在浏览器中的默认样式. 标签的用途:我们学习网页制作时,常常会听到一个词,语义化. 那么什么叫 ...
- php服务器代理解决浏览器跨越问题
详见代码 <?php $url = $_SERVER["QUERY_STRING"]; switch ($_SERVER['REQUEST_METHOD']) { case ...
- ArcGIS JavaScript API动态图层
矢量动态图层 <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Typ ...
- python自动化开发-4
装饰器之我见 python里的装饰器到底是个什么东东,初看起来,可能有的小伙伴会发懵啊,哈哈. 先来个装饰器的例子瞅瞅: Author:RYB # __*__coding:utf-8__*__ ''' ...
- loadrunner 运行脚本-Run-time Settings-Browser Enmulation设置详解
运行脚本-Run-time Settings-Browser Enmulation设置详解 by:授客 QQ:1033553122 浏览器模拟 所有Internet Vuser Header包含一个标 ...
- mybatis学习系列--逆向工程简单使用及mybatis原理
2逆向工程简单测试(68-70) SqlSessionFactory sqlSessionFactory=getSqlSessionFactory(); SqlSession session = sq ...
- SpringBoot项目在新电脑上的配置运行,包括JDK+MAVEN+Git+SpringBoot配置等
该教程记录了我在一台新的电脑上安装IDEA,配置JAVA+MAVEN+GIT+SpringBoot项目的过程,最终完成了项目的运行. 一.若想利用IDEA的git工具从GitHub或者码云上面获取项目 ...
- Mac命令行使用tree查看目录结构
默认tree命令是无法使用的,可以使用homebrew install tree安装. 如果直接使用tree,查看的目录里面含有中文字符的目录或文件时会出现汉字不能显示的问题,可以使用tree -N查 ...
- [Hive_add_2] Hive 数据类型
Hive 数据类型 正常数据类型 # 整型,4个字节 int # 大整型,8个字节 bigint # 字符串,最大长度2G String 复杂数据类型 # 数组,相同类型元素的数组 array< ...