SELECT cpp.product_code AS productCode, cpp.product_name AS productName, cpp.risk_name AS riskName, cpp.risk_code AS riskCode, cpp.project, cpp.rate, cpp.tax_rate AS tax_rate, cpp.age, cpp.pay_period AS payPeriod, cpp.insurance_period AS insurancePeriod, cp.signatory_branch_name AS branchName, cp.signatory_branch_code AS branchCode, cp.protocol_code AS protocolCode, cp.protocol_name AS protocolName FROM coop_protocol_product cpp LEFT JOIN coop_protocol cp ON cpp.coop_protocol_id = cp.id <where> 1 = 1 <if test="dataList != null"> <foreach collection="dataList" index="index" item="list"> or ( <if test="list.riskCode != null and list.riskCode != ''"> cpp.risk_code = #{list.riskCode}</if> <if test="list.productCode != null and list.productCode != ''"> and cpp.product_code = #{list.productCode}</if> <if test="list.payPeriod != null and list.payPeriod != ''"> and cpp.pay_period = #{list.payPeriod}</if> <if test="list.insurancePeriod != null and list.insurancePeriod != ''"> and cpp.insurance_period = #{list.insurancePeriod}</if> <if test="list.age != null and list.age != ''"> and cpp.age = #{list.age}</if> ) </foreach> </if> </where> 这条sql会出错吗

时间: 2023-05-31 11:07:58 浏览: 56
list.riskCode </if> <if test="list.productCode != null and list.productCode != ''">and cpp.product_code = list.productCode </if> ) </foreach> </if> </where> 这个是用于查询保险产品信息的SQL语句,其中包含了产品编码、产品名称、风险名称、风险编码、项目、费率、税率、年龄、缴费期限、保险期限、签约分支机构名称、签约分支机构编码、协议编码、协议名称等信息。通过左连接查询coop_protocol_product表和coop_protocol表,其中coop_protocol_product是保险产品表,coop_protocol是协议表。where语句中的条件是根据参数dataList来添加的,如果dataList不为空,就会循环遍历其中的元素,根据riskCode和productCode是否为空来判断是否需要添加查询条件。
相关问题

function getPagedList(contractId) { var contractId = body.param.ontractId; SELECT a.id, a.conract_id contractId, a.product_id productId, a.purchase_num purchaseNum, a.purchase_price purchasePrice, a.remark, b.product_name productName, b.spec_code specCode, c.type_name typeName, d.unit_code unitCode FROM mes214820519.wms_pur_list_214820519 a, mes214820519.wms_product_214820519 b, mes214820519.wms_product_class_214820519 c, mes214820519.wms_unit_code_214820519 d WHERE a.product_id=b.id AND b.product_class_id = c.id AND b.unit_code_id=d.id `; return db.pager(sql, {contractId: contractId}) } 这段代码的错误在哪

这段代码有两个错误: 1. 在第一行中声明了 `contractId`,但在 SQL 查询语句中使用了 `body.param.ontractId`,应该改为 `body.param.contractId`。 2. SQL 查询语句的末尾多了一个反引号,应该删除它。 正确的代码应该是: ``` function getPagedList(contractId) { var contractId = body.param.contractId; var sql = ` SELECT a.id, a.conract_id contractId, a.product_id productId, a.purchase_num purchaseNum, a.purchase_price purchasePrice, a.remark, b.product_name productName, b.spec_code specCode, c.type_name typeName, d.unit_code unitCode FROM mes214820519.wms_pur_list_214820519 a, mes214820519.wms_product_214820519 b, mes214820519.wms_product_class_214820519 c, mes214820519.wms_unit_code_214820519 d WHERE a.product_id=b.id AND b.product_class_id = c.id AND b.unit_code_id=d.id`; return db.pager(sql, {contractId: contractId}) } ```

function getPagedList(contractId) { var contractId = body.param.contractId; var sql = ` SELECT a.id, a.contract_id contractId, a.product_id productId, a.purchase_num purchaseNum, a.purchase_price purchasePrice, a.remark, b.product_name productName, b.spec_code specCode, c.type_name typeName, d.unitcode unitCode FROM mes214820519.wms_pur_list_214820519 a, mes214820519.wms_product_214820519 b, mes214820519.wms_product_class_214820519 c, mes214820519.wms_unit_code_214820519 d WHERE a.product_id=b.id AND b.product_class_id = c.id AND b.unit_code_id=d.id AND a.contract_id=#{contractId}`; return db.pager(sql, {contractId: contractId}) } 用JavaScript语言修改这段代码

function getPagedList(contractId) { var sql = `SELECT a.id, a.contract_id as contractId, a.product_id as productId, a.purchase_num as purchaseNum, a.purchase_price as purchasePrice, a.remark, b.product_name as productName, b.spec_code as specCode, c.type_name as typeName, d.unitcode as unitCode FROM mes214820519.wms_pur_list_214820519 a INNER JOIN mes214820519.wms_product_214820519 b ON a.product_id = b.id INNER JOIN mes214820519.wms_product_class_214820519 c ON b.product_class_id = c.id INNER JOIN mes214820519.wms_unit_code_214820519 d ON b.unit_code_id = d.id WHERE a.contract_id = :contractId`; return db.pager(sql, { contractId: contractId }); } 在修改后的代码中,我使用了ES6模板字符串来构建SQL语句,同时使用了INNER JOIN来连接多张表,使代码更加简洁易读。另外,我还使用了命名参数代替了原来的占位符,以提高代码的可读性和可维护性。

相关推荐

优化这条sql: select distinct (select product_name from t_product from where id = #{productId} and mark = 1 and status = 1) as productName, (select count(0) from t_clue a where a.distribution_status != 4 and a.mark = 1 and a.product_id = #{productId} and a.status in(1,2,3,31,32,33)) as clueCount, (select count(0) from t_clue a left join t_clue_appendix b on a.clue_code = b.clue_code where a.distribution_status != 4 and a.mark = 1 and b.file_url is not null and a.product_id = #{productId} and a.status in (3,31,32,33)) as intentionCount, (select count(0) from t_clue a where a.status in (4,5,7,8) and a.distribution_status != 4 and a.mark = 1 and a.product_id = #{productId} and a.status = 4) as incomingCount, (select count(0) from t_clue a where a.status in (5,7,8) and a.distribution_status != 4 and a.mark = 1 and a.product_id = #{productId} and a.status in (5,7,8)) as approvedCount, (select count(0) from t_clue a where a.status = 6 and a.distribution_status != 4 and a.mark = 1 and a.product_id = #{productId} and a.status = 6) as rejectionCount, (select count(0) from t_clue a where a.status in (7,8) and a.distribution_status != 4 and a.mark = 1 and a.product_id = #{productId}) as loanCount, (select count(0) from t_clue a where a.status = 8 and a.distribution_status != 4 and a.mark = 1 and a.product_id = #{productId}) as swipeCount, (select sum(a.loan_amount) from t_clue a where a.distribution_status != 4 and a.mark = 1 and a.product_id = #{productId}) as loanMoney, (select sum(a.use_amount) from t_clue a where a.distribution_status != 4 and a.mark = 1 and a.product_id = #{productId}) as swipeMoney

SELECT A.THREEBONAME 三级预算中心, A.PRODUCTNAME2 产品大类, A.PRODUCTCODE4 物料编码, A.PRODUCTNAME4 物料名称, A.天数 活动天数, case when A.天数=0 THEN A.差值 ELSE A.天数 END AS 已持续天数, sum(B.POS_QTY_PCS) 活动数量和, sum(B.POS_QTY_PKG) 活动箱数和, sum(B.POS_AMT) 活动金额和 from (SELECT A.ONEBONAME, A.TWOBONAME, A.THREEBONAME, A.PRODUCTNAME2, A.PRODUCTCODE4, A.PRODUCTNAME4, DATE_FORMAT(A.ACTIVITYSTARTDATE,'%Y%m%d') STARTDATE, DATE_FORMAT(A.ACTIVITYENDDATE,'%Y%m%d') ENDDATE, DATE_FORMAT(DATE_SUB(A.ACTIVITYSTARTDATE, INTERVAL 91 DAY),'%Y%m%d') 未促销开始日期, A.ACTIVITYENDDATE-A.ACTIVITYSTARTDATE+1 天数, to_days(now()) - to_days(A.ACTIVITYSTARTDATE)+1 差值 FROM ka_wantwant_prod.VACTIVITYDETAIL A ) A LEFT JOIN (select A.KA_SYSTEM_CODE, B.BW_SYSTEM_NAME, A.SALES_COM_ID_WH, B.KA_SALES_COM_ID_WH_NAME, B.TPM_THREEBONAME, A.PROD_MATL_ID, A.POS_DATE, A.POS_QTY_PCS, A.POS_QTY_PKG, A.POS_AMT FROM ka_wantwant_prod.tras_ka_pos_history A left join (select distinct C.KA_SALES_COM_ID_WH,C.KA_SALES_COM_ID_WH_NAME,C.BW_SYSTEM_CODE,C.BW_SYSTEM_NAME,C.TPM_THREEBONAME from ka_wantwant_prod.ka_pos_tpm_config C) B on A.KA_SYSTEM_CODE=B.BW_SYSTEM_CODE AND A.SALES_COM_ID_WH=B.KA_SALES_COM_ID_WH ) B ON A.PRODUCTCODE4=B.PROD_MATL_ID AND A.THREEBONAME=B.TPM_THREEBONAME AND B.POS_DATE<=A.ENDDATE AND B.POS_DATE>=A.STARTDATE where DATE_FORMAT(A.STARTDATE,'%Y%m')='202305' and B.POS_QTY_PCS is not null GROUP BY A.THREEBONAME, A.PRODUCTNAME2, A.PRODUCTCODE4, A.PRODUCTNAME4, A.天数, 已持续天数

select a.*, b.name activityName, c.name productName, c.member_max memberMax, d.status as complete, group_concat(if(e.face_value is null, "", e.face_value) separator "\n") as rewardAmount, group_concat(if(e.coupon_code is null, "", e.coupon_code ) separator "\n") as couponCode , group_concat(if(e.coupon_id is null, "", e.coupon_id) separator "\n") as caId from marketing_group_tool_group_member a left join marketing_group_tool_group_info d on a.group_id = d.id left join marketing_group_tool_activity b on a.activity_id = b.activity_id left join marketing_group_tool_product_base c on a.product_id = c.product_id left join marketing_group_tool_send_coupon_record e on (a.group_id = e.group_id and a.card_no = e.card_no) left join wx_recommend_organization organization on b.organization_id = organization.id where ((organization.tree_id between 2002000000000000 and 2002999999999999) or (organization.tree_id between 1000000000000000 and 1999999999999999) or (organization.tree_id between 2000000000000000 and 2999999999999999) or (organization.tree_id between 3000000000000000 and 3999999999999999) or (organization.tree_id between 4000000000000000 and 4999999999999999) or (organization.tree_id between 6000000000000000 and 6999999999999999) or (organization.tree_id between 5000000000000000 and 5999999999999999) or (organization.tree_id between 10000000000000000 and 10999999999999999) or (organization.tree_id between 8000000000000000 and 8999999999999999) or (organization.tree_id between 9000000000000000 and 9999999999999999) or (organization.tree_id between 11000000000000000 and 11999999999999999) or (organization.tree_id between 12000000000000000 and 12999999999999999) or (organization.tree_id between 13000000000000000 and 13999999999999999) or (organization.tree_id between 14000000000000000 and 14999999999999999) or (organization.tree_id between 15000000000000000 and 15999999999999999) or (organization.tree_id between 16000000000000000 and 16999999999999999) or (organization.tree_id between 17000000000000000 and 17999999999999999) ) and 1 = 1 group by a.id, a.activity_id , a.group_id , a.product_id , a.activity_referral_code, a.product_referral_code , a.openid , a.unionid , a.nickname , a.head_img , a.mobile , a.is_sub_buy , a.is_sub_progress , a.is_sub_success , a.sort , a.card_no , a.create_time , a.is_received_notice , a.is_received_progress , a.is_received_success , b.name, c.name, c.member_max , d.status order by a.id desc limit 0,20;

最新推荐

recommend-type

微软内部资料-SQL性能优化5

A clustered index is like a telephone directory in which all of the rows for customers with the same last name are clustered together in the same part of the book. Just as the organization of a ...
recommend-type

后端开发是一个涉及广泛技术和工具的领域.docx

后端开发是一个涉及广泛技术和工具的领域,这些资源对于构建健壮、可扩展和高效的Web应用程序至关重要。以下是对后端开发资源的简要介绍: 首先,掌握一门或多门编程语言是后端开发的基础。Java、Python和Node.js是其中最受欢迎的几种。Java以其跨平台性和丰富的库而著名,Python则因其简洁的语法和广泛的应用领域而备受欢迎。Node.js则通过其基于JavaScript的单线程异步I/O模型,为Web开发提供了高性能的解决方案。 其次,数据库技术是后端开发中不可或缺的一部分。关系型数据库(如MySQL、PostgreSQL)和非关系型数据库(如MongoDB、Redis)各有其特点和应用场景。关系型数据库适合存储结构化数据,而非关系型数据库则更适合处理大量非结构化数据。 此外,Web开发框架也是后端开发的重要资源。例如,Express是一个基于Node.js的Web应用开发框架,它提供了丰富的API和中间件支持,使得开发人员能够快速地构建Web应用程序。Django则是一个用Python编写的Web应用框架,它采用了MVC的软件设计模式,使得代码结构更加清晰和易于维护。
recommend-type

华为数字化转型实践28个精华问答glkm.pptx

华为数字化转型实践28个精华问答glkm.pptx
recommend-type

RTL8188FU-Linux-v5.7.4.2-36687.20200602.tar(20765).gz

REALTEK 8188FTV 8188eus 8188etv linux驱动程序稳定版本, 支持AP,STA 以及AP+STA 共存模式。 稳定支持linux4.0以上内核。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

Redis验证与连接:安装成功验证技巧

![Redis从入门到精通](https://img-blog.csdnimg.cn/6f39d0a2adc3456b96e804eb45032480.png) # 1. Redis安装与验证** ### 2.2 Redis验证方法 Redis验证可以通过以下方法进行: - **命令行验证:** - 打开终端,输入 `redis-cli` 命令进入 Redis 命令行。 - 输入 `ping` 命令,如果返回 "PONG",则表示 Redis 正在运行。 - **客户端验证:** - 使用 Redis 客户端(如 RedisInsight)连接到 Redis 服务器。
recommend-type

3、自定义一个函数int compareStr(char *p1, char *p2),实现两个字符串的比较。相等返回0,大于返回1,小于返回0;编写主函数main()来调用自定义函数完成测试。

下面是自定义的 `compareStr` 函数的代码实现: ```c #include <stdio.h> int compareStr(char *p1, char *p2) { while (*p1 && *p2 && (*p1 == *p2)) { p1++; p2++; } return (*p1 > *p2) - (*p1 < *p2); } int main() { char str1[100], str2[100]; int result; printf("请输入第一个字符串:");
recommend-type

c++校园超市商品信息管理系统课程设计说明书(含源代码) (2).pdf

校园超市商品信息管理系统课程设计旨在帮助学生深入理解程序设计的基础知识,同时锻炼他们的实际操作能力。通过设计和实现一个校园超市商品信息管理系统,学生掌握了如何利用计算机科学与技术知识解决实际问题的能力。在课程设计过程中,学生需要对超市商品和销售员的关系进行有效管理,使系统功能更全面、实用,从而提高用户体验和便利性。 学生在课程设计过程中展现了积极的学习态度和纪律,没有缺勤情况,演示过程流畅且作品具有很强的使用价值。设计报告完整详细,展现了对问题的深入思考和解决能力。在答辩环节中,学生能够自信地回答问题,展示出扎实的专业知识和逻辑思维能力。教师对学生的表现予以肯定,认为学生在课程设计中表现出色,值得称赞。 整个课程设计过程包括平时成绩、报告成绩和演示与答辩成绩三个部分,其中平时表现占比20%,报告成绩占比40%,演示与答辩成绩占比40%。通过这三个部分的综合评定,最终为学生总成绩提供参考。总评分以百分制计算,全面评估学生在课程设计中的各项表现,最终为学生提供综合评价和反馈意见。 通过校园超市商品信息管理系统课程设计,学生不仅提升了对程序设计基础知识的理解与应用能力,同时也增强了团队协作和沟通能力。这一过程旨在培养学生综合运用技术解决问题的能力,为其未来的专业发展打下坚实基础。学生在进行校园超市商品信息管理系统课程设计过程中,不仅获得了理论知识的提升,同时也锻炼了实践能力和创新思维,为其未来的职业发展奠定了坚实基础。 校园超市商品信息管理系统课程设计的目的在于促进学生对程序设计基础知识的深入理解与掌握,同时培养学生解决实际问题的能力。通过对系统功能和用户需求的全面考量,学生设计了一个实用、高效的校园超市商品信息管理系统,为用户提供了更便捷、更高效的管理和使用体验。 综上所述,校园超市商品信息管理系统课程设计是一项旨在提升学生综合能力和实践技能的重要教学活动。通过此次设计,学生不仅深化了对程序设计基础知识的理解,还培养了解决实际问题的能力和团队合作精神。这一过程将为学生未来的专业发展提供坚实基础,使其在实际工作中能够胜任更多挑战。
recommend-type

"互动学习:行动中的多样性与论文攻读经历"

多样性她- 事实上SCI NCES你的时间表ECOLEDO C Tora SC和NCESPOUR l’Ingén学习互动,互动学习以行动为中心的强化学习学会互动,互动学习,以行动为中心的强化学习计算机科学博士论文于2021年9月28日在Villeneuve d'Asq公开支持马修·瑟林评审团主席法布里斯·勒菲弗尔阿维尼翁大学教授论文指导奥利维尔·皮耶昆谷歌研究教授:智囊团论文联合主任菲利普·普雷教授,大学。里尔/CRISTAL/因里亚报告员奥利维耶·西格德索邦大学报告员卢多维奇·德诺耶教授,Facebook /索邦大学审查员越南圣迈IMT Atlantic高级讲师邀请弗洛里安·斯特鲁布博士,Deepmind对于那些及时看到自己错误的人...3谢谢你首先,我要感谢我的两位博士生导师Olivier和Philippe。奥利维尔,"站在巨人的肩膀上"这句话对你来说完全有意义了。从科学上讲,你知道在这篇论文的(许多)错误中,你是我可以依
recommend-type

Linux系统Redis安装:依赖安装与编译全攻略

![Linux系统Redis安装:依赖安装与编译全攻略](https://img-blog.csdnimg.cn/ae7b8258c74742a4918aaae0e34b0603.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAaGFo5p2o5aSn5LuZ,size_20,color_FFFFFF,t_70,g_se,x_16) # 1.1 Redis简介 Redis(Remote Dictionary Server)是一个开源的、内存中的、键值对数据库,用于存储和