SELECT t0.legal_entity_id, t1.attribute_value, t1.attribute_value, t0.long_name, t0.short_name, t1.attribute_value, t1.attribute_value, t1.attribute_value, t1.attribute_value, t1.attribute_value, t0.parent_le_id, t1.attribute_value, t0.classification, t1.attribute_value, T3.last_name, T3.first_name, T3.phone, T3.mailing_address, t1.attribute_value, t3.zipcode, t0.country, t1.attribute_value, t0.le_status, t1.attribute_value, t0.inactive_date, CASE WHEN t0.short_name = '基金内部交易对手' OR t0.short_name = '恒丰_银行总行' THEN 'Y' ELSE 'N' END AS internal_org_flag , CASE WHEN t0.short_name = '基金内部交易对手' OR t0.short_name = '恒丰_银行总行' THEN 'Y' ELSE 'N' END AS is_internal_cpty_flag , CASE WHEN t2.role_name = 'CounterParty' THEN 'Y' ELSE 'N' END AS is_counterparty_flag , CASE WHEN t2.role_name = 'Issuer' THEN 'Y' ELSE 'N' END AS is_asset_issuer_flag , CASE WHEN t2.role_name = 'Agent' THEN 'Y' ELSE 'N' END AS is_custodian_flag , CASE t2.role_name = 'Guarantor' THEN 'Y' ELSE 'N' END AS is_guarantor_flag FROM legal_entity t0 left join le_attribute t1 on T1.legal_entity_id=T0.legal_entity_id left join legal_entity_role t2 on T2.legal_entity_id=T0.legal_entity_id left join le_contact T3 on T3.legal_entity_id=T0.legal_entity_id

时间: 2024-04-01 10:37:05 浏览: 27
这是一个 SQL 查询语句,可能是从某个系统或应用程序中提取数据。这个查询语句包含多个表的连接(使用 LEFT JOIN 关键字),并选择这些表中的一些列作为结果集。以下是对该查询语句中各个部分的解释: 1. SELECT 子句:选择要包含在结果集中的列。这些列来自于多个表,每个列都有一个别名(例如 t0.legal_entity_id 表示 legal_entity 表中的 legal_entity_id 列)。 2. FROM 子句:指定要查询的表以及它们之间的连接方式。这个查询中使用了 LEFT JOIN 关键字,表示左连接,即保留左表中所有行,而右表中没有匹配行的地方填充 NULL 值。 3. WHERE 子句:这个查询中没有 WHERE 子句,表示不对查询结果进行筛选,返回所有符合条件的行。 4. CASE 表达式:这个查询中使用了多个 CASE 表达式,用于根据某些条件返回不同的值。例如,internal_org_flag、is_internal_cpty_flag、is_counterparty_flag 等都是根据 t0.short_name 或 t2.role_name 的值来判断的。 总的来说,这个查询的目的是从多个表中提取一些数据,并对这些数据进行一些处理和转换,最终返回符合条件的行。
相关问题

语法分析:SELECT wt.transaction_id ,we.organization_id ,we.wip_entity_id ,decode(wt.line_id, NULL, we.wip_entity_name, '')

这是一个SQL查询语句,用于从一个或多个表中检索数据。具体来说,该查询语句包含以下列: - wt.transaction_id:表示从wt表中选择transaction_id列。 - we.organization_id:表示从we表中选择organization_id列。 - we.wip_entity_id:表示从we表中选择wip_entity_id列。 - decode(wt.line_id, NULL, we.wip_entity_name, ''):该表达式使用DECODE函数,将wt表中的line_id列的值与NULL比较。如果它是NULL,则选择we表中的wip_entity_name列的值。否则,选择一个空字符串。 该查询语句将返回一个结果集,其中包含上述列的值。

优化sql:SELECT we.organization_id ,we.wip_entity_id ,case when wl.line_id is null then we.wip_entity_name else '' end wip_entity_name ,we.primary_item_id ,mtt.transaction_type_name ,mmt.transaction_date ,bd.department_code ,mmt.inventory_item_id ,mmt.subinventory_code ,mta.reference_account ,br.resource_code ,lu2.meaning as line_type_name ,mta.base_transaction_value ,mta.cost_element_id ,flv.meaning as cost_element ,wdj.class_code job_type_code ,ml.meaning job_type_name FROM (select * from gerp.mtl_material_transactions where substr(transaction_date,1,7) >= '2023-06' and transaction_source_type_id = 5) mmt inner join gerp.wip_entities we on mmt.organization_id = we.organization_id inner join gerp.mtl_transaction_accounts mta on mta.transaction_source_id = we.wip_entity_id and mta.transaction_id = mmt.transaction_id and mta.transaction_source_type_id = 5 inner join gerp.mtl_transaction_types mtt on mtt.transaction_type_id = mmt.transaction_type_id inner join mfg_lookups lu2 on lu2.lookup_code = mta.accounting_line_type and lu2.lookup_type = 'CST_ACCOUNTING_LINE_TYPE' inner join gerp.mtl_system_items_b msi on msi.inventory_item_id = mmt.inventory_item_id and msi.organization_id = mta.organization_id left join gerp.bom_departments bd on bd.department_id = mmt.department_id left join gerp.bom_resources br on br.resource_id = mta.resource_id left join gerp.wip_lines wl on wl.line_id = mmt.repetitive_line_id left join gerp.wip_discrete_jobs wdj on wdj.wip_entity_id = mta.transaction_source_id left join gerp.fnd_lookup_values_vl flv on cast(mta.cost_element_id as string) = flv.lookup_code and flv.lookup_type = 'CST_COST_CODE_TYPE' left join mfg_lookups ml on ml.lookup_code = wdj.job_type and ml.lookup_type = 'WIP_DISCRETE_JOB' 。其中mmt,we,mta,msi,wdj数据量很大

针对这个SQL语句,可以优化的地方有: 1. 使用JOIN语句时,可以根据数据量大小,将数据量大的表放在后面,这样可以避免在连接时出现性能问题。 2. 使用子查询时,可以在子查询中添加条件筛选,减少返回的数据量。 3. 可以对查询中的日期条件进行优化,例如使用日期范围查询时,可以使用BETWEEN关键字代替大于等于和小于等于的运算符。 4. 可以对大表进行分区或分片,以加快查询速度。 5. 可以对JOIN语句中的字段添加索引,以提高查询效率。 下面是对原SQL语句的优化: ``` SELECT we.organization_id, we.wip_entity_id, CASE WHEN wl.line_id is null THEN we.wip_entity_name ELSE '' END wip_entity_name, we.primary_item_id, mtt.transaction_type_name, mmt.transaction_date, bd.department_code, mmt.inventory_item_id, mmt.subinventory_code, mta.reference_account, br.resource_code, lu2.meaning as line_type_name, mta.base_transaction_value, mta.cost_element_id, flv.meaning as cost_element, wdj.class_code job_type_code, ml.meaning job_type_name FROM gerp.wip_entities we INNER JOIN ( SELECT * FROM gerp.mtl_material_transactions WHERE transaction_date BETWEEN '2023-06-01' AND '2023-06-30' AND transaction_source_type_id = 5 ) mmt ON mmt.organization_id = we.organization_id INNER JOIN gerp.mtl_transaction_accounts mta ON mta.transaction_source_id = we.wip_entity_id AND mta.transaction_id = mmt.transaction_id AND mta.transaction_source_type_id = 5 INNER JOIN gerp.mtl_transaction_types mtt ON mtt.transaction_type_id = mmt.transaction_type_id INNER JOIN mfg_lookups lu2 ON lu2.lookup_code = mta.accounting_line_type AND lu2.lookup_type = 'CST_ACCOUNTING_LINE_TYPE' INNER JOIN gerp.mtl_system_items_b msi ON msi.inventory_item_id = mmt.inventory_item_id AND msi.organization_id = mta.organization_id LEFT JOIN gerp.bom_departments bd ON bd.department_id = mmt.department_id LEFT JOIN gerp.bom_resources br ON br.resource_id = mta.resource_id LEFT JOIN gerp.wip_lines wl ON wl.line_id = mmt.repetitive_line_id LEFT JOIN gerp.wip_discrete_jobs wdj ON wdj.wip_entity_id = mta.transaction_source_id LEFT JOIN gerp.fnd_lookup_values_vl flv ON cast(mta.cost_element_id as string) = flv.lookup_code AND flv.lookup_type = 'CST_COST_CODE_TYPE' LEFT JOIN mfg_lookups ml ON ml.lookup_code = wdj.job_type AND ml.lookup_type = 'WIP_DISCRETE_JOB'; ``` 在优化后的SQL语句中,将子查询中的日期范围查询放在了WHERE语句中,将数据量较大的表放在了后面,左连接的表也放在了后面。同时,可以根据具体情况对需要添加索引的字段进行索引优化。

相关推荐

SELECT DISTINCT c.ID AS id, c.NAME AS contName, c.CONTRACT_NO AS contractNo, c.INSTANCE_ID AS instanceId, c.UNDERTAKE_DEPT_ID AS remindDeptId, c.UNDERTAKE_DEPT_NAME AS sendDeptName, c.CREATE_USER_ID, c.CREATE_USER_NAME AS contractOpteraterName, c.PLAN_STATE AS planState, c.PLAN_STATE_NAME AS planStateName, aw.INSTANCE_ID AS inId, aw.CREATE_TIME AS sendTime FROM ( SELECT c.* FROM ( SELECT c.* FROM ( SELECT c.ORIGINAL_CONTRACT_ID, MAX(CREATE_TIME) CREATE_TIME FROM CONTRACT_DRAFT.C_CONTRACT_INFO c WHERE c.ORIGINAL_CONTRACT_ID IS NOT NULL AND c.ORIGINAL_CONTRACT_ID != '' GROUP BY c.ORIGINAL_CONTRACT_ID ) t LEFT JOIN CONTRACT_DRAFT.C_CONTRACT_INFO c ON t.ORIGINAL_CONTRACT_ID = c.ORIGINAL_CONTRACT_ID AND t.CREATE_TIME = c.CREATE_TIME UNION ALL SELECT c.* FROM CONTRACT_DRAFT.C_CONTRACT_INFO c WHERE ( c.ORIGINAL_CONTRACT_ID IS NULL OR c.ORIGINAL_CONTRACT_ID = '' ) AND c.ID NOT IN ( SELECT c.ORIGINAL_CONTRACT_ID FROM CONTRACT_DRAFT.C_CONTRACT_INFO c WHERE c.ORIGINAL_CONTRACT_ID IS NOT NULL AND c.ORIGINAL_CONTRACT_ID != '')) c WHERE c.deleted_flag = 0 AND c.BELONG = 1 AND sysdate > c.end_date AND c.plan_state IN (4100, 4110, 4120, 4200, 4210, 4220, 5100, 5110, 5120) ) c INNER JOIN (SELECT INSTANCE_ID,create_time,state FROM CONTRACT_DRAFT.C_ACTIVITY_WORKITEMS WHERE state = 'Waiting') aw ON c.INSTANCE_ID = aw.INSTANCE_ID LEFT JOIN (SELECT deleted_flag,CONT_ID FROM CONTRACT_DRAFT.C_GET_PAY_PLAN WHERE deleted_flag = 0 ) g ON c.ID = g.CONT_ID LEFT JOIN CONTRACT_DRAFT.C_OUR_ENTITY_INFO oe ON c.OUR_ENTITY_ID = oe.ID AND oe.DELETED_FLAG = 0 ORDER BY aw.CREATE_TIME DESC 优化

改如何修正: <select id="getCurrentTask" resultType="com.sottop.sokonmobile.sokonmobile.qingdao.entity.AsEmWorkOrderEntity"> SELECT asewo.code_s as code,asewo.order_type_s as orderType,asewo.equipment_name_s as equipmentName,asewo.executor_s as executor, asewo.plan_start_time_T as planStartTime,asewo.plan_finish_time_T as planFinishTime,asewo.tpm_key_s as tpmKey,asewo.shop_s as shop, asewo.line_S as line,asewo.actual_start_time_t as startTime,asewo.actual_finish_time_t as finishTime,asewo.executor_account_s as executorAccounts, asewo.source_type_s as sourceType,asewo.SOURCE_ORDER_S as sourceOrder,asewo.CREATION_TIME as creationTime FROM AT_AS_EM_Work_Order asewo WHERE to_char(asewo.plan_start_time_T,'yyyy_mm-dd hh24:mi') <= to_char(plan_finish_time_T,'yyyy_mm_dd hh24:mi') AND asewo.ORDER_STATUS_S='创建' AND asewo.executor_s=#{executor} <if test="orderType!=null and orderType!=''"> AND asewo.order_type_s=#{orderType} </if> ORDER BY asewo.creation_time DESC Union All SELECT asewo.code_s as code,asewo.order_type_s as orderType,asewo.equipment_name_s as equipmentName,asewo.executor_s as executor, asewo.plan_start_time_T as planStartTime,asewo.plan_finish_time_T as planFinishTime,asewo.tpm_key_s as tpmKey,asewo.shop_s as shop, asewo.line_S as line,asewo.actual_start_time_t as startTime,asewo.actual_finish_time_t as finishTime,asewo.executor_account_s as executorAccounts, asewo.source_type_s as sourceType,asewo.SOURCE_ORDER_S as sourceOrder,asewo.CREATION_TIME as creationTime FROM AT_AS_EM_Work_Order asewo WHERE asewo.ORDER_STATUS_S='创建' AND asewo.executor_s=#{executor} <if test="orderType!=null and orderType!=''"> AND asewo.order_type_s=#{orderType} </if> ORDER BY asewo.creation_time DESC </select>

优化以下Oracle语句: SELECT SUBSTR(msn.serial_number, 1, 10) genset_sn, msi2.segment1 Genset_BOM_NUM, msi2.inventory_item_id, msi.segment1 key_component, mut1.serial_number component_sn, msi.description component_desc, wdj.date_completed, (SELECT MAX(aps.vendor_name) FROM ap_suppliers aps, bom_resources bor, mtl_unit_transactions mut, po_headers_all poh, po_lines_all pol, wip_osp_resources_val_v wor WHERE aps.vendor_id = poh.vendor_id AND bor.resource_id = wor.resource_id AND poh.po_header_id = pol.po_header_id AND pol.item_id = bor.purchase_item_id AND wor.wip_entity_id = mut.transaction_source_id AND mut.serial_number = mut1.serial_number AND mut.inventory_item_id = mut1.inventory_item_id AND mut.organization_id = mut1.organization_id AND mut.receipt_issue_type = 2 AND mut.transaction_source_type_id = 5 ) supplier FROM mtl_material_transactions mmt1, mtl_material_transactions mmt2, mtl_parameters mpa, mtl_serial_numbers msn, mtl_system_items msi, mtl_system_items msi2, mtl_transaction_types mtt1, mtl_transaction_types mtt2, mtl_unit_transactions mut1, mtl_unit_transactions mut2, wip_discrete_jobs_v wdj WHERE mmt1.inventory_item_id = mut1.inventory_item_id AND mmt1.organization_id = mut1.organization_id AND WDJ.PRIMARY_ITEM_ID = msi2.INVENTORY_ITEM_ID AND mmt1.transaction_id = mut1.transaction_id AND mmt1.transaction_source_id = wdj.wip_entity_id AND mmt1.transaction_type_id = mtt1.transaction_type_id AND mtt1.transaction_type_name = 'WIP Issue' AND NOT EXISTS (SELECT 'WIP Negative Issue or WIP Return' FROM mtl_material_transactions mmt3, mtl_transaction_types mtt3, mtl_unit_transactions mut3 WHERE mmt3.transaction_id = mut3.transaction_id AND mmt3.transaction_type_id = mtt3.transaction_type_id AND mmt3.transaction_date > mmt1.transaction_date AND mtt3.transaction_type_name IN ('WIP Negative Issue', 'WIP Return') AND mut3.serial_number = mut1.serial_number AND mut3.inventory_item_id = mut1.inventory_item_id) AND mmt2.transaction_id = mut2.transaction_id AND mmt2.transaction_source_id = wdj.wip_entity_id AND mmt2.transaction_type_id = mtt2.transaction_type_id AND mtt2.transaction_type_name = 'WIP Completion' AND mpa.organization_code = 'WHP' AND msn.current_organization_id = mpa.organization_id AND LENGTH(msn.serial_number) >= 10 AND msi.inventory_item_id = mmt1.inventory_item_id AND msi.organization_id = mmt1.organization_id AND (msi.planning_make_buy_code = 2 OR msi.segment1 LIKE 'SO%') AND mut2.serial_number = msn.serial_number AND mut2.inventory_item_id = msn.inventory_item_id AND mut2.organization_id = mpa.organization_id AND msi2.ORGANIZATION_ID = '323'

最新推荐

recommend-type

Code_First_使用Entity._Framework编程.docx

Entity Framework(EF)是Microsoft开发的一个ORM(对象关系映射)工具,用于.NET框架和Visual Studio,简化数据库操作。在Code First开发模式下,开发者直接通过C#代码定义领域模型,而不是通过XML文件(如EDMX)来...
recommend-type

C# Newtonsoft.Json各种操作案例、PDF

对于Entity Framework、DataTable和DataSet的支持,Newtonsoft.Json提供了方便的方法直接序列化和反序列化这些数据结构,简化了数据的存储和传输。 总之,Newtonsoft.Json在C#开发中扮演着关键角色,提供了一套全面...
recommend-type

Android程序报错程序包org.apache.http不存在问题的解决方法

主要介绍了Android程序报错"程序包org.apache.http不存在——Android 6.0已经不支持HttpClient" 问题的解决方法,感兴趣的小伙伴们可以参考一下
recommend-type

Java泛型的用法及T.class的获取过程解析

T o = (T) getHibernateTemplate().get(entityClass, id); return o; } } ``` 这个示例代码中,我们使用了反射的API来获取T.class。首先,我们使用`getClass()`方法获取当前类的Class对象,然后使用`...
recommend-type

LTE_PHY协议解读.doc

在LTE(Long Term Evolution)技术中,物理层(PHY)是通信系统的基础,它负责数据传输的底层处理,包括编码、调制、频率分配和错误检测。本文档详细解读了LTE物理层的各个方面,旨在提供一个全面的理解。 首先,3G...
recommend-type

基于Springboot的医院信管系统

"基于Springboot的医院信管系统是一个利用现代信息技术和网络技术改进医院信息管理的创新项目。在信息化时代,传统的管理方式已经难以满足高效和便捷的需求,医院信管系统的出现正是适应了这一趋势。系统采用Java语言和B/S架构,即浏览器/服务器模式,结合MySQL作为后端数据库,旨在提升医院信息管理的效率。 项目开发过程遵循了标准的软件开发流程,包括市场调研以了解需求,需求分析以明确系统功能,概要设计和详细设计阶段用于规划系统架构和模块设计,编码则是将设计转化为实际的代码实现。系统的核心功能模块包括首页展示、个人中心、用户管理、医生管理、科室管理、挂号管理、取消挂号管理、问诊记录管理、病房管理、药房管理和管理员管理等,涵盖了医院运营的各个环节。 医院信管系统的优势主要体现在:快速的信息检索,通过输入相关信息能迅速获取结果;大量信息存储且保证安全,相较于纸质文件,系统节省空间和人力资源;此外,其在线特性使得信息更新和共享更为便捷。开发这个系统对于医院来说,不仅提高了管理效率,还降低了成本,符合现代社会对数字化转型的需求。 本文详细阐述了医院信管系统的发展背景、技术选择和开发流程,以及关键组件如Java语言和MySQL数据库的应用。最后,通过功能测试、单元测试和性能测试验证了系统的有效性,结果显示系统功能完整,性能稳定。这个基于Springboot的医院信管系统是一个实用且先进的解决方案,为医院的信息管理带来了显著的提升。"
recommend-type

管理建模和仿真的文件

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

字符串转Float性能调优:优化Python字符串转Float性能的技巧和工具

![字符串转Float性能调优:优化Python字符串转Float性能的技巧和工具](https://pic1.zhimg.com/80/v2-3fea10875a3656144a598a13c97bb84c_1440w.webp) # 1. 字符串转 Float 性能调优概述 字符串转 Float 是一个常见的操作,在数据处理和科学计算中经常遇到。然而,对于大规模数据集或性能要求较高的应用,字符串转 Float 的效率至关重要。本章概述了字符串转 Float 性能调优的必要性,并介绍了优化方法的分类。 ### 1.1 性能调优的必要性 字符串转 Float 的性能问题主要体现在以下方面
recommend-type

Error: Cannot find module 'gulp-uglify

当你遇到 "Error: Cannot find module 'gulp-uglify'" 这个错误时,它通常意味着Node.js在尝试运行一个依赖了 `gulp-uglify` 模块的Gulp任务时,找不到这个模块。`gulp-uglify` 是一个Gulp插件,用于压缩JavaScript代码以减少文件大小。 解决这个问题的步骤一般包括: 1. **检查安装**:确保你已经全局安装了Gulp(`npm install -g gulp`),然后在你的项目目录下安装 `gulp-uglify`(`npm install --save-dev gulp-uglify`)。 2. **配置
recommend-type

基于Springboot的冬奥会科普平台

"冬奥会科普平台的开发旨在利用现代信息技术,如Java编程语言和MySQL数据库,构建一个高效、安全的信息管理系统,以改善传统科普方式的不足。该平台采用B/S架构,提供包括首页、个人中心、用户管理、项目类型管理、项目管理、视频管理、论坛和系统管理等功能,以提升冬奥会科普的检索速度、信息存储能力和安全性。通过需求分析、设计、编码和测试等步骤,确保了平台的稳定性和功能性。" 在这个基于Springboot的冬奥会科普平台项目中,我们关注以下几个关键知识点: 1. **Springboot框架**: Springboot是Java开发中流行的应用框架,它简化了创建独立的、生产级别的基于Spring的应用程序。Springboot的特点在于其自动配置和起步依赖,使得开发者能快速搭建应用程序,并减少常规配置工作。 2. **B/S架构**: 浏览器/服务器模式(B/S)是一种客户端-服务器架构,用户通过浏览器访问服务器端的应用程序,降低了客户端的维护成本,提高了系统的可访问性。 3. **Java编程语言**: Java是这个项目的主要开发语言,具有跨平台性、面向对象、健壮性等特点,适合开发大型、分布式系统。 4. **MySQL数据库**: MySQL是一个开源的关系型数据库管理系统,因其高效、稳定和易于使用而广泛应用于Web应用程序,为平台提供数据存储和查询服务。 5. **需求分析**: 开发前的市场调研和需求分析是项目成功的关键,它帮助确定平台的功能需求,如用户管理、项目管理等,以便满足不同用户群体的需求。 6. **数据库设计**: 数据库设计包括概念设计、逻辑设计和物理设计,涉及表结构、字段定义、索引设计等,以支持平台的高效数据操作。 7. **模块化设计**: 平台功能模块化有助于代码组织和复用,包括首页模块、个人中心模块、管理系统模块等,每个模块负责特定的功能。 8. **软件开发流程**: 遵循传统的软件生命周期模型,包括市场调研、需求分析、概要设计、详细设计、编码、测试和维护,确保项目的质量和可维护性。 9. **功能测试、单元测试和性能测试**: 在开发过程中,通过这些测试确保平台功能的正确性、模块的独立性和系统的性能,以达到预期的用户体验。 10. **微信小程序、安卓源码**: 虽然主要描述中没有详细说明,但考虑到标签包含这些内容,可能平台还提供了移动端支持,如微信小程序和安卓应用,以便用户通过移动设备访问和交互。 这个基于Springboot的冬奥会科普平台项目结合了现代信息技术和软件工程的最佳实践,旨在通过信息化手段提高科普效率,为用户提供便捷、高效的科普信息管理服务。