clear markdown feedback
clear markdown feedback
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0. 3798892 fiddles created (41833 in the last week).

select version();
version()
8.0.27
 hidden batch(es)


CREATE TABLE crm_leads ( id INTEGER NOT NULL PRIMARY KEY, lead_source INTEGER, lead_status INTEGER, sub_status INTEGER, enquiry_date datetime );
 hidden batch(es)


CREATE TABLE crm_sources ( id INTEGER NOT NULL PRIMARY KEY, title VARCHAR (50) );
 hidden batch(es)


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');
 hidden batch(es)


INSERT INTO crm_sources VALUES (1, 'Business Card'), (2, 'Direct Call'), (3, 'Facebook'), (4, 'LinkedIn');
 hidden batch(es)


select * from crm_sources
id title
1 Business Card
2 Direct Call
3 Facebook
4 LinkedIn
 hidden batch(es)


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
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
 hidden batch(es)