为联接子句创建表子查询

时间:2019-05-20 07:09:28

标签: sql oracle

所以这里的问题是neo_product_benefit中的OPTION_NAME与其他表没有关系,但是它通过OPTION_ID列与neo_claims_pmb_details表有关系,并且在neo_claims_pmb_details表中具有BENEFIT_ID列,可以将其连接到其他表。

简而言之

我不完全确定SQL如何获得OPTION_NAME并将其联接到其他表,所以我认为创建一个临时表可以正常工作并将其联接然后再删除它,但是我不知道如何语法会起作用

任何帮助将不胜感激。

SELECT        a.batch_id, 
              a.claim_id, 
              a.cover_no, 
              a.receive_date, 
              a.practice_no, 
              a.service_provider_no, 
              a.refering_provider_no, 
              b.claim_line_id, 
              b.dependent_code, 
              b.service_date_from, 
              b.service_date_to, 
              b.cheque_run_date, 
              b.process_date, 
              b.tariff_code_no, 
              b.tariff_amount, 
              b.claimed_amount, 
              c.amount_paid, 
              d.practice_name, 
              e.discipline, 
              e.discipline_description, 
              g.rule_no, 
              g.message_code, 
              g.long_msg_description, 
              h.benefit_code, 
              h.benefit_description, 
              t.option_name 

    FROM      neo_claims a 

    LEFT JOIN neo_claim_line b 
    ON        (a.claim_id = b.claim_id) 

    LEFT JOIN neo_claim_line_benefit c 
    ON        (b.claim_line_id = c.claim_line_id)

    LEFT JOIN neo_practice_details d 
    ON        ( a.practice_no = d.practice_no) 

    LEFT JOIN neo_sub_disciplines e 
    ON        ( d.sub_discipline = e.sub_discipline) 

    LEFT JOIN neo_claimline_firings g 
    ON        (b.claim_line_id = g.claim_line_id)

    LEFT JOIN neo_product_benefit h 
    ON        (c.benefit_id = h.benefit_id)

              ( 
                     SELECT i.*, 
                            j.* 
                     INTO   temp_table 
                     FROM   neo_claims_pmb_details j, 
                            neo_product_optin i)

    LEFT JOIN temp_table t 
    ON        ( j.benefit_id = t.benefit_id) 
    WHERE     a.batch_id = 3496584;
    DROP TABLE temp_table;

2 个答案:

答案 0 :(得分:0)

您可以加入两个表,并添加相关的(左或内部)连接..在我的示例中,表的别名为tx和ty

并根据您的评论创建表

  swapOneCard = () => {
    const currentHand = this.state.hand
    //get random card to remove from current hand
    const cardToRemove = currentHand[Math.floor(Math.random() * currentHand.length)];
    //all cards
    const allCards = this.state.cards
    //unchoosen cards to choose from
    const unchoosenCards = allCards.filter((card) => {
      return !currentHand.includes(card)
    })
    //get random card from unchoosen cards
    var cardToAdd = unchoosenCards[Math.floor(Math.random() * unchoosenCards.length)];

    const newHand = currentHand.map((card) => {
      if(card == cardToRemove){
        return cardToAdd
      } else {
        return card
      }
    })

    this.setState({
      hand: newHand
    })
  }

答案 1 :(得分:0)

我的猜测是不需要临时表。只需在原始查询中包含表表达式即可

{{1}}