我有以下查詢:沒有組聚合列由
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的預期結果。 –