如何通过内联接来消除选择结果中的重复项?

时间:2019-05-16 19:50:40

标签: sql oracle oracle11g

我想知道如何在INNER JOIN中投射重复项。

顺便说一句,我有一个要求,要求我以这种形式返回2300万行:

field1      field2      field3      field4      field5
  a           k           c           u           j
  o           y           c           t           m
  r           k           z           u           d
  a           k           c           x           w
  d           y           q           t           h

我想删除field2和field4具有相同值的行,并保留为这些重复项的第一行。 我预期的结果是:

field1      field2      field3      field4      field5
  a           k           c           u           j
  o           y           c           t           m
  a           k           c           x           w

在我要对其应用此处理的代码下面。我需要在代码底部提供帮助和建议。谢谢

    SELECT 
    cd_box,
    cd_charact,
    txt_charact_value,
    row_id,
    val_charact_value,
    dttm_charact_value,
    cd_param,
    val_charact
FROM (
    SELECT 
         code_element AS cd_box,
         code_caracteristique, 
         valeur_t AS txt_charact_value, 
         null as row_id,
         valeur_n AS val_charact_value,
         valeur_d AS dttm_charact_value, 
         index_tableau AS val_charact, 
         valeur_liste,
         code_type_element,
         cd_charact,
         cd_param,
         code_caracteristique_metro
    FROM (
        SELECT 
             code_element,
             code_caracteristique, 
             valeur_texte, 
             valeur_num, 
             valeur_date, 
             index_tableau, 
             valeur_liste,
             code_type_element,
             idtype_valeur,
             CASE  
                WHEN (idtype_valeur=1 OR idtype_valeur=2) AND (valeur_texte!='null' AND valeur_texte='t') THEN 'OUI'
                WHEN (idtype_valeur=1 OR idtype_valeur=2) AND (valeur_texte!='null' AND valeur_texte='f') THEN 'NON'
                --ELSE 'null'
             END AS valeur_t,
             CASE  
                WHEN (idtype_valeur=9 OR idtype_valeur=10 OR idtype_valeur=11) THEN TO_CHAR(valeur_num)
                --ELSE 'null'
             END AS valeur_n,
             CASE  
                WHEN (idtype_valeur=3 OR idtype_valeur=5) THEN TO_CHAR(valeur_date)
                --ELSE 'null'
             END AS valeur_d
        FROM (
            SELECT 
                code_element,
                code_caracteristique, 
                valeur_texte, 
                valeur_num, 
                valeur_date, 
                index_tableau, 
                valeur_liste,
                code_type_element,
                idtype_valeur
            FROM (
                SELECT 
                  ec.code_element, 
                  ec.code_caracteristique, 
                  ec.valeur_texte, 
                  ec.valeur_num, 
                  ec.valeur_date, 
                  ec.index_tableau, 
                  ec.valeur_liste,
                  e.code_type_element
                FROM 
                  stg_element_caracteristique ec,   
                  stg_element e,
                  stg_caracteristique c,
                  stg_modele_caracteristique mc
                WHERE e.code=ec.code_element AND c.name = ec.code_caracteristique
                AND c.idmodele_caracteristique = mc.id 
                AND mc.idtype_valeur != 6
                AND (ec.valeur_liste='null' OR ec.valeur_liste is null)
                AND ec.code_caracteristique!='TE_GENER_DATE_MES'
            ) table1
            INNER JOIN (
                SELECT 
                  stg_caracteristique.name, 
                  stg_type_element.code,
                  stg_modele_caracteristique.idtype_valeur
                FROM 
                  stg_caracteristique, 
                  stg_type_element,
                  stg_modele_caracteristique
                WHERE 
                  stg_caracteristique.idtype_element = stg_type_element.id 
                  AND stg_modele_caracteristique.id = stg_caracteristique.idmodele_caracteristique   
                  AND stg_type_element.code != 'TE_GENER'
                ORDER BY stg_type_element.code
            ) table2
            ON (table1.code_caracteristique = table2.name AND table1.code_type_element = table2.code)
        ) 
    ) charact1
    INNER JOIN ( --le dernier lk
        SELECT 
          cd_code as cd_charact,
          code_param as cd_param,
          code_caracteristique_metro
        FROM 
          stg_reprisemaskeqrevu
    ) row1 
    ON (charact1.code_caracteristique = row1.code_caracteristique_metro) 
) WHERE cd_box IS NOT NULL OR cd_box!='null'

1 个答案:

答案 0 :(得分:1)

SQL表表示无序集。除非有列指定顺序,否则没有 first 值。尽管我将let free = allAlbums[indexPath.row].free if free == "1" { self.performSegue(withIdentifier: "caseDetail", sender: self) } else { self.performSegue(withIdentifier: "paidCase", sender: self) } 保留为该名称的占位符,但让我假设这样的列。

然后您基本上想使用 series_count = 2 while series_count <= ws.max_column: #searches sheet for color-coded data and pulls it into series. for s in range(2, ws.max_column + 1): series_list = [] for c in range(4, ws.max_row + 1): cell = ws.cell(row = c, column = series_count) if cell.fill.start_color.index == 9: series_list.append(cell.value) elif cell.fill.start_color.index == 8: series_name = cell.value else: pass if len(series_list) > 0: print "Adding", series_name, series_list chart_data.add_series(series_name, series_list, '0%') else: pass series_count += 1

?