我有三个具有外键关系的数据表,但是当我进行查询时,它会出现错误,如Syntax error or access violation: 1055 Expression #22 of SELECT list is not in GROUP BY clause and contains nonaggregated column invoices.imported'
下面是我的桌子结构
jobs
id invoice_no customer_id
1 H045 1
2 A041 2
job_detials
id job_id est_start_date est_off_date
1 1 04-01-2017 01-01-2017
2 1 05-02-2017 03-06-2017
3 1 01-05-2017 17-04-2017
4 2 14-04-2017 15-02-2017
5 2 12-04-2017 03-04-2017
invoices
id job_id imported
1 1 1
2 2 0以及我试图执行结果的查询。
select `jobs`.`id` as `job_id`, `invoices`.`imported`,
MIN(job_details.est_start_date) as est_start_date, MAX(job_details.est_off_date) as est_off_date, `jobs`.`invoice_no` from `jobs`
left join `job_details` on `job_details`.`job_id`= `jobs`.`id` left join `invoices` on `invoices`.`job_id` = `jobs`.`id`
group by `jobs`.`id`有人能帮我解决这个错误吗。?谢谢
发布于 2017-06-22 18:15:28
在许多SQL数据库中,必须对所有非聚合字段进行GROUP BY;在本例中,需要按job_id、imported和invoice_no进行分组。
在某些配置下,MySQL确实允许您省略这样的字段,但是最近的默认值倾向于限制这样的语法,因为选择invoices.imported这样的内容,它不是主键被分组的表的一部分,而不对其进行分组可能会产生不确定的结果。
https://stackoverflow.com/questions/44706661
复制相似问题