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

Requêtes MySQL Discussion :

Erreur Mixing of GROUP columns dans la requête


Sujet :

Requêtes MySQL

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé
    Homme Profil pro
    Technicien maintenance
    Inscrit en
    Mai 2008
    Messages
    382
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France, Loire (Rhône Alpes)

    Informations professionnelles :
    Activité : Technicien maintenance
    Secteur : Industrie

    Informations forums :
    Inscription : Mai 2008
    Messages : 382
    Par défaut Erreur Mixing of GROUP columns dans la requête
    Bonjour à tous,

    Je viens de changer d'hébergeur et mon code n'est plus valable:
    Voici mon erreur:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause
    Plus exactement voici ce que j'obtiens dans la console:
    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
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    FATAL - com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause
    FATAL - 	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    FATAL - 	at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    FATAL - 	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    FATAL - 	at java.lang.reflect.Constructor.newInstance(Unknown Source)
    FATAL - 	at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)
    FATAL - 	at com.mysql.jdbc.Util.getInstance(Util.java:384)
    FATAL - 	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1054)
    FATAL - 	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3566)
    FATAL - 	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3498)
    FATAL - 	at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1959)
    FATAL - 	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2113)
    FATAL - 	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2568)
    FATAL - 	at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2113)
    FATAL - 	at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2275)
    FATAL - 	at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:96)
    FATAL - 	at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:96)
    FATAL - 	at com.pforissier.dao.tables.MembresDao.select_groupby(MembresDao.java:386)
    FATAL - 	at com.pforissier.model.CalculSynthese_stocks.<init>(CalculSynthese_stocks.java:63)
    FATAL - 	at com.pforissier.vue.Synthese_stocksPanel$7.actionPerformed(Synthese_stocksPanel.java:351)
    FATAL - 	at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
    FATAL - 	at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
    FATAL - 	at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
    FATAL - 	at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    FATAL - 	at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
    FATAL - 	at java.awt.Component.processMouseEvent(Unknown Source)
    FATAL - 	at javax.swing.JComponent.processMouseEvent(Unknown Source)
    FATAL - 	at java.awt.Component.processEvent(Unknown Source)
    FATAL - 	at java.awt.Container.processEvent(Unknown Source)
    FATAL - 	at java.awt.Component.dispatchEventImpl(Unknown Source)
    FATAL - 	at java.awt.Container.dispatchEventImpl(Unknown Source)
    FATAL - 	at java.awt.Component.dispatchEvent(Unknown Source)
    FATAL - 	at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    FATAL - 	at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    FATAL - 	at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    FATAL - 	at java.awt.Container.dispatchEventImpl(Unknown Source)
    FATAL - 	at java.awt.Window.dispatchEventImpl(Unknown Source)
    FATAL - 	at java.awt.Component.dispatchEvent(Unknown Source)
    FATAL - 	at java.awt.EventQueue.dispatchEvent(Unknown Source)
    FATAL - 	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    FATAL - 	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    FATAL - 	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    FATAL - 	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    FATAL - 	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    FATAL - 	at java.awt.EventDispatchThread.run(Unknown Source)

    Voici ma requête "Bato":
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    SELECT m.id, m.nom, m.prenom, m.passe, SUM(m.solde) AS nombre, m.afficher, m.admin, m.forfait FROM membres m
    Plus exactement la méthode concerné:
    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
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    public ArrayList<Membres> select_groupby() {
    		connect= JdbcConnector.getInstance();
    		try {
    			try {
    	            prepare = this.connect.prepareStatement(
    	            		"SELECT m.id, m.nom, m.prenom, m.passe, SUM(m.solde) AS nombre, m.afficher, m.admin, m.forfait "+
    	            		"FROM membres m ");
     
    				//On exécute la requête
    				resultat = prepare.executeQuery();
    				int i=0;
     
    				while(resultat.next()){
    					table.add(i, new Membres(resultat.getInt("m.id"), resultat.getString("m.nom"), resultat.getString("m.prenom"), resultat.getString("m.passe"), 
    							resultat.getFloat("nombre"), resultat.getInt("m.afficher"), resultat.getInt("m.admin"), resultat.getInt("m.forfait")));
    					i++;
    				}
     
    			} catch (SQLException e) {
    				e.printStackTrace();
    			} finally {
    				if (resultat != null) {
    					resultat.close();
    				}
    				if (prepare != null) {
    					prepare.close();
    				}  
    				if (connect != null) {
    					connect.close();
    				} 
    			}
    		} catch (SQLException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    		return table;
    	}
    Merci de m'éclairer sur cette erreur!

  2. #2
    Expert confirmé
    Homme Profil pro
    Inscrit en
    Mai 2002
    Messages
    3 173
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Rhône (Rhône Alpes)

    Informations forums :
    Inscription : Mai 2002
    Messages : 3 173
    Par défaut
    Bonjour,

    vous utilisez une fonction d'agrégation (ici sum) sans utilisez de group by.

    Donc ca ne peut pas marcher.

    lisez ceci : http://sqlpro.developpez.com/cours/sqlaz/ensembles/

    Sinon pour aller plus loin pourquoi voulelz-vous faire une SUM sur le solde ?

    Si votre modélisation est correct ca n'a pas de sens à ce niveau là

  3. #3
    Membre éclairé
    Homme Profil pro
    Technicien maintenance
    Inscrit en
    Mai 2008
    Messages
    382
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France, Loire (Rhône Alpes)

    Informations professionnelles :
    Activité : Technicien maintenance
    Secteur : Industrie

    Informations forums :
    Inscription : Mai 2008
    Messages : 382
    Par défaut
    Je viens juste de comprendre mon erreur.

    Enfaite l'objectif est d'avoir la somme de la colonne solde sur la totalité des lignes.
    Je ne veux donc pas de regroupement par group By.

    Les autres champs ne servent a rien, je les met pour rester dans l'esprit de ma table Objet.

    Comment faire pour modifier cette requête?

  4. #4
    Expert confirmé
    Homme Profil pro
    Inscrit en
    Mai 2002
    Messages
    3 173
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Rhône (Rhône Alpes)

    Informations forums :
    Inscription : Mai 2002
    Messages : 3 173
    Par défaut
    Beh,

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    select sum(ma_col)
    from ma_table

  5. #5
    Membre éclairé
    Homme Profil pro
    Technicien maintenance
    Inscrit en
    Mai 2008
    Messages
    382
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France, Loire (Rhône Alpes)

    Informations professionnelles :
    Activité : Technicien maintenance
    Secteur : Industrie

    Informations forums :
    Inscription : Mai 2008
    Messages : 382
    Par défaut
    Merci, J'ai modifié mes requêtes.

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

Discussions similaires

  1. Réponses: 1
    Dernier message: 18/03/2012, 10h59
  2. Erreur : Mixing of GROUP columns
    Par lmabire dans le forum Requêtes
    Réponses: 4
    Dernier message: 07/11/2011, 14h37
  3. 2 GROUP BY dans une requête
    Par dorian53 dans le forum Requêtes
    Réponses: 4
    Dernier message: 09/10/2009, 15h30
  4. Erreur de lecture de données dans une requête SQL
    Par PtiteDéveloppeuse dans le forum Requêtes
    Réponses: 0
    Dernier message: 10/01/2008, 12h29
  5. [MySQL] ERROR:Mixing of GROUP columns
    Par Angelik dans le forum PHP & Base de données
    Réponses: 5
    Dernier message: 01/02/2007, 16h54

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