新的oracle,需要连接表来获取我的结果集中的字段值

时间:2010-12-15 15:17:47

标签: sql oracle

我知道sql server而不是oracle,所以我会用sql server语言来描述我需要的oracle。

我正在开发一个oracle查询,需要选择以下详细说明的字段。我在BUG表中找到了除了两个之外的所有内容。另外两个在其他表中,我不清楚如何进入我的oracle SQL。

我还希望将Oracle中定义的字段名称转换为对我来说更有意义的字段名称,并且将dame作为我的sql表中的字段名称猥亵。 (这是oracle extract / sql2005插入作业的一部分)这可能需要oricalafied导致我以sql方式编写它并且只是期望它工作...让我知道。

我的sql到目前为止 - 我添加''作为我需要加入的2个字段的占位符:

BG_SUBJECT字段是ALL_LISTS表的一部分,其中AL_ITEM_ID是主键。

DetectedInRelease是RELEASES表中的REL_NAME字段,其中REL_ID是主键。

SELECT 
bg_user_56 AS Project, 
bg_user_60 AS SubSystem, 
BG_USER_81 AS AssignedToUserName, 
bg_responsible AS AssignedTo,  
bg_status AS Status, 
BG_USER_15 AS BusinessFunction, 
bg_detection_date AS DetectedOnDate, 
BG_SEVERITY AS BusinessSeverity,  
bg_user_36 AS TestingSeverity, 
bg_bug_id AS DefectID, 
Bg_User_09 AS EstFixedDate,
bg_user_25 AS EstReadyForRetest,
BG_DESCIPTION AS description, 
BG_USER_03 AS DetectedInDeploymentEvent, 
'' AS DetectedInRelease,--- ??? not in bug table !!!!
BG_USER_47 AS FunctionalAreaWorkstream,
BG_USER_19 AS PlannedFixInDeploymentEvent, 
BG_USER_55 AS PlannedFixInRelease,
BG_USER_57 AS PTMTestManager, 
Bg_User_58 AS RemediatingCTOName, 
'' AS Subject,--- ??? not in bug table !!!
bg_summary AS Summary, 
bg_user_80 AS MLTestEnvironment, 
GETDATE() AS LoadDateTime,
bg_user_12 AS Deferred 
FROM tascs_ml_bac_transition_db.BUG

2 个答案:

答案 0 :(得分:0)

我准备采取这个措施​​:

SELECT 
bg_user_56 AS Project, 
bg_user_60 AS SubSystem, 
BG_USER_81 AS AssignedToUserName, 
bg_responsible AS AssignedTo,  
bg_status AS Status, 
BG_USER_15 AS BusinessFunction, 
bg_detection_date AS DetectedOnDate, 
BG_SEVERITY AS BusinessSeverity,  
bg_user_36 AS TestingSeverity, 
bg_bug_id AS DefectID, 
Bg_User_09 AS EstFixedDate,
bg_user_25 AS EstReadyForRetest,
BG_DESCIPTION AS description, 
BG_USER_03 AS DetectedInDeploymentEvent, 
rel.BG_DetectedInRelease AS DetectedInRelease,--- ??? not in bug table !!!!
BG_USER_47 AS FunctionalAreaWorkstream,
BG_USER_19 AS PlannedFixInDeploymentEvent, 
BG_USER_55 AS PlannedFixInRelease,
BG_USER_57 AS PTMTestManager, 
Bg_User_58 AS RemediatingCTOName, 
al.BG_SUBJECT AS Subject,--- ??? not in bug table !!!
bg_summary AS Summary, 
bg_user_80 AS MLTestEnvironment, 
GETDATE() AS LoadDateTime,
bg_user_12 AS Deferred 
FROM tascs_ml_bac_transition_db.BUG B, ALL_LISTS al, releases rel
WHERE al.al_item_id = b.al_item_id and rel.rel_id = b.rel_id;

很难猜测这是否有效,因为我没有这些表的完整DDL,但这是我根据你给出的最佳猜测。我假设BUG的字段名称与您需要加入的字段相同。这可能无效,请随时澄清。

如果您愿意,也可以使用INNER JOIN ON语法。

答案 1 :(得分:0)

查询语法实际上是相同的,但是GETDate需要是SYSDATE,作为示例内连接包含在内

SELECT 
        BUG.bg_user_56         AS Project                    ,
        BUG.bg_user_60        AS SubSystem                  ,
        BUG.BG_USER_81        AS AssignedToUserName         ,
        BUG.bg_responsible    AS AssignedTo                 ,
        BUG.bg_status         AS Status                     ,
        BUG.BG_USER_15        AS BusinessFunction           ,
        BUG.bg_detection_date AS DetectedOnDate             ,
        BUG.BG_SEVERITY       AS BusinessSeverity           ,
        BUG.bg_user_36        AS TestingSeverity            ,
        BUG.bg_bug_id         AS DefectID                   ,
        BUG.Bg_User_09        AS EstFixedDate               ,
        BUG.bg_user_25        AS EstReadyForRetest          ,
        BUG.BG_DESCIPTION     AS description                ,
        BUG.BG_USER_03        AS DetectedInDeploymentEvent  ,
        REL.REL_NAME          AS DetectedInRelease          , --- ??? not in bug table !!!!
        BUG.BG_USER_47        AS FunctionalAreaWorkstream   ,
        BUG.BG_USER_19        AS PlannedFixInDeploymentEvent,
        BUG.BG_USER_55        AS PlannedFixInRelease        ,
        BUG.BG_USER_57        AS PTMTestManager             ,
        BUG.Bg_User_58        AS RemediatingCTOName         ,
        al.BG_SUBJECT         AS Subject                    , --- ??? not in bug table !!!
        BUG.bg_summary        AS Summary                    ,
        BUG.bg_user_80        AS MLTestEnvironment          ,
        sysdate               AS LoadDateTime               , --changed to sysdate
        BUG.bg_user_12        AS Deferred
FROM 
      tascs_ml_bac_transition_db.BUG BUG
      INNER JOIN 
      ALL_LISTS al
            ON BUG.AL_ITEM_ID = al.AL_ITEM_ID --THIS ASSUMES AL_ITEM_ID IS COMMON FIELD
      INNER JOIN 
      RELEASES REL
            ON BUG.REL_ID     = REL.REL_ID --THIS ASSUMES REL_ID IS COMMON FIELD