Paste this into a new question or an answer at dba.stackexchange.com:
<!-- --> > select version(); > > <pre> > | version() | > | :-------- | > | 8.0.27 | > </pre> <!-- --> > CREATE TABLE crm_leads > ( > id INTEGER NOT NULL PRIMARY KEY, > lead_source INTEGER, > lead_status INTEGER, > sub_status INTEGER, > enquiry_date datetime > > ); > > <pre> > ✓ > </pre> <!-- --> > CREATE TABLE crm_sources > ( > id INTEGER NOT NULL PRIMARY KEY, > title VARCHAR (50) > ); > > <pre> > ✓ > </pre> <!-- --> > INSERT INTO crm_leads VALUES > (3, 2, 1, 6,'2021-10-02'), (4, 1, 3, 3,'2021-05-01'), > (5, 4, 8, 6,'2020-10-01'), (6, 4, 1, 3,'2021-10-06'), > (10, 2, 1, 3,'2021-10-06'), (11, 3, 5, 6,'2021-01-01'); > > <pre> > ✓ > </pre> <!-- --> > INSERT INTO crm_sources VALUES > (1, 'Business Card'), (2, 'Direct Call'), (3, 'Facebook'), (4, 'LinkedIn'); > > <pre> > ✓ > </pre> <!-- --> > select * from crm_sources > > <pre> > id | title > -: | :------------ > 1 | Business Card > 2 | Direct Call > 3 | Facebook > 4 | LinkedIn > </pre> <!-- --> > SELECT `l`.`lead_status`, `crm_sources`.`title`, > count(*) as leadnum, `l`.`enquiry_date` > FROM `crm_leads` as `l` LEFT JOIN `crm_sources` > ON `crm_sources`.`id`= `l`.`lead_source` WHERE `lead_status` <> 10 > GROUP BY `l`.`lead_status`, `crm_sources`.`title` > ORDER BY `leadnum` DESC, `crm_sources`.`title` ASC, `l`.`lead_status` ASC > > <pre> > Expression #4 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'db_1730840799.l.enquiry_date' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by > </pre> *db<>fiddle [here](https://dbfiddle.uk/?rdbms=mysql_8.0&fiddle=65b310b4b973a7577d4953e01c09a124)*
back to fiddle