IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Oracle Discussion :

Aide pour incrémentation row_number() over (partition by order by)


Sujet :

Oracle

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre actif
    Femme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Septembre 2012
    Messages
    38
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Septembre 2012
    Messages : 38
    Par défaut Aide pour incrémentation row_number() over (partition by order by)
    Je souhaite compter le nombre de chlore, niveau, turb pour chaque entité ARBRI, MPECQ.

    J'ai essayé avec row_number() over (partition by order by), SANS SUCCES !
    Soit je conserve le second champ entier et donc cela incrémente de 1 (puisque les noms sont différents), soit je tronque et ne retient que les 3 premières lettres et ne parvient plus à faire le lien avec la données initiales.

    ARBRI CHLORE_ANS
    ARBRI CHLORE_CIT
    ARBRI CHLORE_PECQ
    ARBRI CHLORE_SORT_BASSE
    ARBRI CHLORE_SORT_HAUTE
    ARBRI CHLORE_SORT_UT
    ARBRI NITRATE
    ARBRI NIV_D
    ARBRI NIV_G
    ARBRI PRES_ESOIL
    ARBRI PRES_PECQ
    ARBRI PRES_SORT_BASSE
    ARBRI PRES_SORT_HAUTE
    ARBRI TURBI_ANS
    ARBRI TURBI_PECQ
    ARBRI TURBI_SORT
    MPECQ CHLORE_ENT
    MPECQ CHLORE_SORT
    MPECQ NIV_D
    MPECQ NIV_G
    MPECQ NIV_REF

    Merci pour votre aide.

  2. #2
    Modérateur
    Avatar de escartefigue
    Homme Profil pro
    bourreau
    Inscrit en
    Mars 2010
    Messages
    10 599
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Loir et Cher (Centre)

    Informations professionnelles :
    Activité : bourreau
    Secteur : Finance

    Informations forums :
    Inscription : Mars 2010
    Messages : 10 599
    Billets dans le blog
    10
    Par défaut
    Bonjour,

    En ce qui me concerne, c'est clair comme du jus de boudin

    Donnez un exemple de jeu de données en entrée, la description des tables (avec le format des colonnes), les index, et le résultat attendu

  3. #3
    McM
    McM est déconnecté
    Expert confirmé

    Homme Profil pro
    Développeur Oracle
    Inscrit en
    Juillet 2003
    Messages
    4 580
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Développeur Oracle

    Informations forums :
    Inscription : Juillet 2003
    Messages : 4 580
    Billets dans le blog
    4
    Par défaut
    En effet, pas super clair si tu veux juste un regroupement par entite ou pour chaque ligne un compteur par "groupe de produit"

    Tu peux très bien au niveau partition, d'une fonction analytique, mettre du SUBSTR pour avoir une fenêtre précise

    Dans ce code, j'ai pris l'option de ne garder que les données avant le '_' (attention au cas où il n'y en a pas)
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    WITH T AS (SELECT 'ARBRI' entite, 'CHLORE_ANS' produit FROM dual
    UNION ALL SELECT 'ARBRI', 'CHLORE_CIT' FROM dual
    UNION ALL SELECT 'ARBRI', 'CHLORE_PECQ' FROM dual
    UNION ALL SELECT 'ARBRI', 'CHLORE_SORT_BASSE' FROM dual
    UNION ALL SELECT 'ARBRI', 'CHLORE_SORT_HAUTE' FROM dual
    UNION ALL SELECT 'ARBRI', 'CHLORE_SORT_UT' FROM dual
    UNION ALL SELECT 'ARBRI', 'NITRATE' FROM dual
    UNION ALL SELECT 'ARBRI', 'NIV_D' FROM dual
    UNION ALL SELECT 'ARBRI', 'NIV_G' FROM dual
    UNION ALL SELECT 'ARBRI', 'PRES_ESOIL' FROM dual
    UNION ALL SELECT 'ARBRI', 'PRES_PECQ' FROM dual
    UNION ALL SELECT 'ARBRI', 'PRES_SORT_BASSE' FROM dual
    UNION ALL SELECT 'ARBRI', 'PRES_SORT_HAUTE' FROM dual
    UNION ALL SELECT 'ARBRI', 'TURBI_ANS' FROM dual
    UNION ALL SELECT 'ARBRI', 'TURBI_PECQ' FROM dual
    UNION ALL SELECT 'ARBRI', 'TURBI_SORT' FROM dual
    UNION ALL SELECT 'MPECQ', 'CHLORE_ENT' FROM dual
    UNION ALL SELECT 'MPECQ', 'CHLORE_SORT' FROM dual
    UNION ALL SELECT 'MPECQ', 'NIV_D' FROM dual
    UNION ALL SELECT 'MPECQ', 'NIV_G' FROM dual
    UNION ALL SELECT 'MPECQ', 'NIV_REF' FROM dual
    )
    SELECT  entite, produit, SUBSTR(produit, 1, INSTR(produit, '_')-1) grp, row_number() OVER (PARTITION BY entite, SUBSTR(produit, 1, INSTR(produit, '_')-1) ORDER BY produit) nb
    FROM t
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    ENTITE	PRODUIT	GRP	NB
    ARBRI	CHLORE_ANS	CHLORE	1
    ARBRI	CHLORE_CIT	CHLORE	2
    ARBRI	CHLORE_PECQ	CHLORE	3
    ARBRI	CHLORE_SORT_BASSE	CHLORE	4
    ARBRI	CHLORE_SORT_HAUTE	CHLORE	5
    ARBRI	CHLORE_SORT_UT	CHLORE	6
    ARBRI	NIV_D	NIV	1
    ARBRI	NIV_G	NIV	2
    ARBRI	PRES_ESOIL	PRES	1
    ARBRI	PRES_PECQ	PRES	2
    ARBRI	PRES_SORT_BASSE	PRES	3
    ARBRI	PRES_SORT_HAUTE	PRES	4
    ARBRI	TURBI_ANS	TURBI	1
    ARBRI	TURBI_PECQ	TURBI	2
    ARBRI	TURBI_SORT	TURBI	3
    ARBRI	NITRATE		1
    MPECQ	CHLORE_ENT	CHLORE	1
    MPECQ	CHLORE_SORT	CHLORE	2
    MPECQ	NIV_D	NIV	1
    MPECQ	NIV_G	NIV	2
    MPECQ	NIV_REF	NIV	3

  4. #4
    Membre actif
    Femme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Septembre 2012
    Messages
    38
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Septembre 2012
    Messages : 38
    Par défaut MERCI
    Merci beaucoup McM !

    Ca marche super.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [XL-2007] Besoin d'aide pour créer un tableau qui va incrémenter automatiquement des onglets
    Par Bernardini dans le forum Macros et VBA Excel
    Réponses: 0
    Dernier message: 28/02/2015, 17h40
  2. Réponses: 13
    Dernier message: 10/07/2013, 16h07
  3. Besoin d'aide pour l'I.A. d'un puissance 4
    Par Anonymous dans le forum C
    Réponses: 2
    Dernier message: 25/04/2002, 17h05
  4. Une petite aide pour les API ?
    Par Yop dans le forum Windows
    Réponses: 2
    Dernier message: 04/04/2002, 21h45

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo