如何从复杂的SQL查询中了解源表

时间:2016-04-18 11:43:14

标签: mysql sql plsql

PFB查询中我想知道我可以找到的实际表格( pin_ein,engineer_pin,transaction_date,EFFECTIVE_WEEK )....

select count(1),pin_ein,engineer_pin,transaction_date,EFFECTIVE_WEEK from 
       (SELECT vw1.pin_ein, vw1.engineer_pin,
                               vw1.transaction_date, vw1.effective_week,
                               vw1.stores_tools_cost,
                               (vw1.stores_total_cost - vw1.stores_tools_cost
                               ) stores_total_cost_excl_tools,
                               vw1.item_count, vw1.stores_visit_count,
                               CASE
                                  WHEN vw1.stores_total_cost <
                                         5
                                     THEN vw1.stores_visit_count
                               END stores_low_cost_visit_count,
                               vw1.actual_ouc ouc, er.eng_name engineer_name,
                               CASE
                                  WHEN c.home_parked IS NOT NULL
                                     THEN c.home_parked
                                  ELSE 'N'
                               END home_parker,
                               CASE
                                  WHEN c.home_parked IS NOT NULL
                                     THEN c.commute_time
                                  ELSE -99
                               END commute_time,
                               vw1.stores_com_cost ---v9.3---
                          FROM (SELECT   pin_ein, engineer_pin, actual_ouc,
                                         transaction_date, effective_week,
                                         NVL
                                            (SUM
                                                (CASE
                                                    WHEN (   cow LIKE '%TOOL%'
                                                          OR cow LIKE
                                                                     '%TOOLE%'
                                                         )
                                                       THEN transaction_value
                                                 END
                                                ),
                                             0
                                            ) stores_tools_cost,
                                         SUM
                                            (transaction_value
                                            ) stores_total_cost,
                                         SUM (transaction_quantity)
                                                                   item_count,
                                         COUNT
                                            (DISTINCT sta_code
                                            ) stores_visit_count,
                                         NVL
                                            (SUM
                                                (CASE
                                                    WHEN cow in (SELECT cow FROM orbit_odw.stores_cow_ref)
                                                       THEN transaction_value
                                                 END
                                                ),
                                             0
                                            ) stores_com_cost     ---v9.3---
                                    FROM orbit_odw.stores_transaction_dtls
                                   WHERE effective_week BETWEEN 201543
                                                            AND 201610
                                     /***Ver 6.0---last 13 weeks data to be considered***/
                                     AND transaction_date
                                            BETWEEN to_date('19-10-2015','dd-mm-yyyy')
                                                AND to_date('06-03-2016','dd-mm-yyyy')
                                /***Ver 6.0---last 13 weeks data to be considered***/
                                GROUP BY pin_ein,
                                         engineer_pin,
                                         actual_ouc,
                                         transaction_date,
                                         effective_week) vw1,
                               (SELECT *
                                  FROM orbit_odw.dim_wms_rmdm
                                 WHERE current_status = 1) er,
                               (SELECT engineer_ein, commute_time,
                                       home_parked
                                  FROM orbit_odw.eng_parking_at_home_dtls
                                 WHERE rec_end_date > SYSDATE
                                   AND home_parked = 'Y') c
                         WHERE TO_CHAR (vw1.pin_ein) = er.ein
                           AND vw1.pin_ein = c.engineer_ein(+))  group by pin_ein,engineer_pin,transaction_date,EFFECTIVE_WEEK having count(1)>1; 

请帮忙.. 提前致谢

1 个答案:

答案 0 :(得分:1)

基本上,如果我正确理解你的问题。您需要了解外部SELECT从哪里获取数据。因此,有一个简单的规则集用于获取这些数据。步骤如下。

  • 检查色谱柱输出,即您的情况 pin_ein,engineer_pin,TRANSACTION_DATE,EFFECTIVE_WEEK
  • 检查外部查询所在的内联视图或表 获取数据。在您的情况下,它是您唯一的内联视图 使用 - &gt;所以有点容易识别:P
  • 现在确定内联视图VW1如何填充数据。在你的 案例表orbit_odw.stores_transaction_dtls用于填充 必填项目。

希望这些信息是必需的。此外,对于简单查询,您始终可以转到ALL_TAB_COLUMNS系统表以轻松识别表的列。