sql group by query,only_full_group_by错误

时间:2016-09-28 15:41:37

标签: mysql sql group-by

我正在尝试在我的sql上运行以下查询:

SELECT `post_id` , `userto`, `userfrom` , noti_type, id FROM tbl_notification WHERE userto = '2' GROUP BY post_id,noti_type

但它给了我这个错误:

Error Code: 1055. Expression #4 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'vinpedb.tbl_notification.userfrom' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

现在问题是我无法从sql_mode中删除“only_full_group_by”,所以这不是一个选项,因为我没有权限这样做。

我可以做些什么来修改查询以适应新规则并支持only_full_group_by吗?

我正在尝试将以下内容分组:

id  userto  userfrom  post_id  noti_type

1     2        4        4       post_like
2     2        1        3       post_like
3     2        4        3       post_like
4     2        8        3       post_like
14    2        7        3       post_comm
15    2        12       3       post_comm
19    2        4        5       post_like

结果应该是

id  userto  userfrom  post_id  noti_type

1     2        4        4       post_like
4     2        8        3       post_like
15    2        12       3       post_comm
19    2        4        5       post_like

(如果你不能回答这个问题,请将此标记为重复,因为这不是,在所有其他帖子中,人们只有1个解决方案来更改sql模式,我无法做到)

0 个答案:

没有答案
相关问题