为什么我不能在MySQL中的GROUP BY查询中使用多个列?

时间:2017-03-28 13:06:21

标签: mysql group-by mysql-error-1064

我需要创建一个按三个不同列分组的sql,这是我的查询:

SELECT 
    notification.type, 
    notification.triggerer, 
    notification.to_what,
    ANY_VALUE(user_data.name) AS name,
    ANY_VALUE(user_data.surname) AS surname,
    ANY_VALUE(user_data.avatarimage) AS avatarimage,
    COUNT(*) AS counter
FROM notification 
INNER JOIN user_data
    ON notification.triggerer = user_data.owner
WHERE notification.owner = "c6cecc891f6c4cc84cc0b62062578e52"
    AND isdelete=0
ORDER BY notification.id DESC
GROUP BY notification.triggerer, notification.type, notification.to_what
LIMIT 0,100

但是当我这样做时,它会显示一个错误:

> #1064 - You have an error in your SQL syntax; check the manual that corresponds 
to your MySQL server version for the right syntax to use near 
'GROUP BY notification.triggerer, notification.type, notification.to_what
LIMIT ' at line 15

我该如何解决?

1 个答案:

答案 0 :(得分:1)

您可以使用它,但您的<form>必须在$something = $this->input->post('something');

之前
group by