Optimization of greater than operator

前端 未结 3 511
不知归路
不知归路 2021-01-25 05:09

credit table and validtransaction table have million record data from year 2008 onwards.

We are doing a migration. So I need to find out the credittypeids which are no

3条回答
  •  忘了有多久
    2021-01-25 06:01

    This should return your (distinct!) list of CREDITTYPEID that were used in the past, but are not used curretnly (after PERIODSEQ 1055)

    SELECT CREDITTYPEID  /* used before 1055 */
    FROM CREDITTYPE ct
    WHERE PERIODSEQ < 1055
    MINUS
    SELECT CREDITTYPEID /* used after 1055 */
    FROM CREDITTYPE ct
    WHERE PERIODSEQ>=1055;
    

    As the column name suggest CREDITTYPEID is a type so there are several rows in the table with the same typeId.

    The query above return only the distinct list and uses no hash anti join.

    You may add parallel option (with the PARALLEL hint) if your HW allows it.

提交回复
热议问题