mysql, distinct, cakephp

Par romses, il y a 8 ans


Bonjour,

Depuis j'ai un soucis avec mysql je n'arrive pas à faire des requetes groupées sur une table

Ce que je fais

Voici la structure de ma table

CREATE TABLE `colis` ( `id` int(11) NOT NULL, `frais` int(11) NOT NULL, `nom_expediteur` varchar(255) NOT NULL, `telephone_expediteur` varchar(255) NOT NULL, `nom_destinataire` varchar(255) NOT NULL, `telephone_destinataire` varchar(255) NOT NULL, `valeur` int(11) NOT NULL, `nature` text NOT NULL, `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `modified` datetime DEFAULT NULL, `etat` int(11) DEFAULT '1', `user_id` int(11) NOT NULL, `agence_id` int(11) NOT NULL, `agence_id1` int(11) NOT NULL, `code_colis` varchar(255) DEFAULT NULL, `residence_expediteur` varchar(100) DEFAULT NULL, `slug` varchar(500) DEFAULT NULL, `nom_autre_destinataire` varchar(255) DEFAULT NULL, `prenom_autre_destinataire` varchar(255) DEFAULT NULL, `numero_autre_destinataire` varchar(255) DEFAULT NULL, `phone_autre_destinataire` varchar(255) DEFAULT NULL, `date_retrait` datetime DEFAULT NULL, `lieu_payement` varchar(100) DEFAULT NULL, `type_payement` varchar(100) DEFAULT NULL, `provenance` varchar(100) DEFAULT 'online', `numero_facture` int(11) DEFAULT NULL, `passage` int(11) DEFAULT NULL, `cloture_caisse` int(11) DEFAULT '0', `idsession` varchar(100) DEFAULT NULL, `date_reception` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', `agent_retrait` int(11) DEFAULT '0', `sync` int(11) DEFAULT '0' ) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE `agences` ( `id` int(11) NOT NULL, `nom_agence` varchar(255) NOT NULL, `ville` varchar(255) NOT NULL, `localisation` varchar(255) NOT NULL, `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `modified` datetime DEFAULT NULL, `etat` int(11) NOT NULL DEFAULT '1', `entreprise_id` int(11) NOT NULL, `phone` varchar(255) DEFAULT NULL, `sync` int(11) NOT NULL DEFAULT '0' ) ENGINE=InnoDB DEFAULT CHARSET=utf8;

voici le code SQL que je fais

$colis = $this->Colis->find()->select(['frais', 'code_colis','nature','telephone_expediteur','Colis.created','Colis.slug','nom_expediteur','nom_destinataire','Colis.etat','type_payement'])->distinct(['code_colis'])->contain(['Agences']); $colis = $this->paginate($colis);

Ce que je veux

je veux la liste groupé par code colis par agence

Ce que j'obtiens

Error: SQLSTATE[42000]: Syntax error or access violation: 1055 Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'mybd.Colis.frais' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

Aucune réponse