我有以下查询:没有组聚合列由
select
count(*) as leads,
(select count(*) from assignments where lead_id=leads.id and deleted_at is null) as assignments,
(select count(*) from assignments where lead_id=leads.id and deleted_at is not null) as returns,
date_format(leads.updated_at, "%m/%d/%Y") as date
from `leads` where leads.updated_at between "2017-08-24 04:00:00" and "2017-08-26 03:59:59"
group by `date`
这产生了以下错误:
SQLSTATE[42000]: Syntax error or access violation: 1055 Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'leadbind.leads.id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by (SQL: select count() as leads, (select count() from assignments where lead_id=leads.id and deleted_at is null) as assignments, (select count(*) from assignments where lead_id=leads.id and deleted_at is not null) as returns, date_format(leads.updated_at, "%m/%d/%Y") as date from
leads
where leads.updated_at between "2017-08-24 04:00:00" and "2017-08-26 03:59:59" group bydate
)
是否有可能解决此同时仍保持group by date
?我想保留子查询。
如果'updated_at'是DATETIME或TIMESTAMP,那么你的回答是错误的。无论如何,它不回答这个问题。 –
再试一次... – maSTAShuFu
现在它解决了这个错误,但可能不会给出OP的预期结果。 –