【发布时间】:2014-03-14 15:44:30
【问题描述】:
我有两个多连接查询。 1 用于来自“会话”表的产品,另一个用于来自“包装”表的产品。这两个查询都必须加入我的 order 和 order_items 表。
在我们的订单列表网页中,单个订单应如下所示:
|order id | products|
|123 | A2,PKG1 |
每个单独的查询组连接产品,但我如何对来自两个不同连接查询的连接产品进行分组?
我最初的想法是连接表,但我的同事说只使用对象。
我真的不想编写代码/构造对象,因为产品只是为了展示。
任何人都可以提出快速简单的建议吗?除了连接表或使用对象之外的任何内容。
这是我的 2 个查询:
会话: 选择 ats_store.order.payment_type,production_www.paypal_transactions.createdOn 作为 order_date,production_www.paypal_transactions.FIRSTNAME 作为名字, production_www.paypal_transactions.LASTNAME 作为姓氏,ats_store.order.id 作为 order_id,ats_store.order.customerid,ats_store.order.shipping_address_id,ats_store.order.status,ats_store.order_items.product_id,ats_store.shipping_address.country 作为国家,ats_store。 shipping_address.street_1 作为 street1,ats_store.shipping_address.street_2 作为 street2,ats_store.shipping_address.street_3 作为 street3,ats_store.shipping_address.city 作为城市,ats_store.shipping_address.state_and_province 作为州,ats_store.shipping_address.zip_code 作为 zip,GROUP_CONCAT(production_cache_salesforce_repl. ats_conference_session__c.Name order by production_cache_salesforce_repl.ats_conference_session__c.Sort_Code__c) 作为产品,production_cache_salesforce_repl.ats_conference_session__c.Sort_Code__c 来自 ats_store.order 左加入 ats_store.shipping_address on ats_store.shipping_address.id = ats_store.order.shipping_address_id 内部加入 ats_store.order_items on ats_store.order_items.order_id = ats_store.order.id INNER JOIN production_cache_salesforce_repl.ats_store_price__c price ON price.Id = ats_store.order_items.product_id 加入 production_cache_salesforce_repl.ats_conference_session__c ON production_cache_salesforce_repl.ats_conference_session__c.Id = price.ATS_Conference_Session__c 左加入 production_www.paypal_transactions ON production_www.paypal_transactions.id = ats_store.order.paypal_transaction_id 其中 ats_store.order.shipping_address_id != -1 和 production_www.paypal_transactions.COMMENT1 = 'ATS 网上商店' 和 production_www.paypal_transactions.RESPMSG = '已批准' 按 ats_store.order.id 分组 按 order_date 排序
包: 选择 ats_store.order.payment_type,production_www.paypal_transactions.createdOn 作为 order_date,production_www.paypal_transactions.FIRSTNAME 作为名字, production_www.paypal_transactions.LASTNAME 作为姓氏,ats_store.order.id 作为 order_id,ats_store.order.customerid,ats_store.order.shipping_address_id,ats_store.order.status,ats_store.order_items.product_id,ats_store.shipping_address.country 作为国家,ats_store。 shipping_address.street_1 作为 street1, ats_store.shipping_address.street_2 作为 street2,ats_store.shipping_address.street_3 作为 street3,ats_store.shipping_address.city 作为城市, ats_store.shipping_address.state_and_province 作为州,ats_store.shipping_address.zip_code 作为 zip, GROUP_CONCAT(production_cache_salesforce_repl.ats_store_package__c.Package_Code__c order by production_cache_salesforce_repl.ats_store_package__c.Package_Code__c) 作为产品 来自 ats_store.order 左加入 ats_store.shipping_address on ats_store.shipping_address.id = ats_store.order.shipping_address_id 内部加入 ats_store.order_items on ats_store.order_items.order_id = ats_store.order.id INNER JOIN production_cache_salesforce_repl.ats_store_price__c price ON price.Id = ats_store.order_items.product_id 加入 production_cache_salesforce_repl.ats_store_package__c ON production_cache_salesforce_repl.ats_store_package__c.Id = price.ATS_Store_Package__c 左加入 production_www.paypal_transactions ON production_www.paypal_transactions.id = ats_store.order.paypal_transaction_id 其中 ats_store.order.shipping_address_id != -1 和 production_www.paypal_transactions.COMMENT1 = 'ATS 网上商店' 和 production_www.paypal_transactions.RESPMSG = '已批准' 按 ats_store.order.id 分组 按 order_date 排序
【问题讨论】: