MYSQL升级GROUP BY子句;这与sql_mode = only_full_group_by不兼容

时间:2016-09-22 11:07:51

标签: mysql

我们升级了MYSQL数据库;

SELECT l.subscriberid AS subscriberid FROM email_list_subscribers AS l, email_queues AS q 
            WHERE q.recipient = l.subscriberid AND q.queueid = 2343 AND queuetype = 'send' 
            AND l.listid IN (31) GROUP BY l.emailaddress HAVING COUNT(l.emailaddress) > 1

现在我们得到了

#1055 - Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'emailmarketer.l.subscriberid' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

我们能做什么?

1 个答案:

答案 0 :(得分:1)

试试这个:

SELECT l.emailaddress,
       GROUP_CONCAT(l.subscriberid) AS subscriberids
FROM email_list_subscribers l JOIN
     email_queues  q 
     ON q.recipient = l.subscriberid 
WHERE q.queueid = 2343 AND queuetype = 'send' AND
      l.listid IN (31)
GROUP BY l.emailaddress
HAVING COUNT(l.emailaddress) > 1;

注意:

  • 从不FROM子句中使用逗号。 始终使用明确,正确的JOIN语法。
  • 返回每封电子邮件的订阅者列表。
  • 如果有重复项,您可能需要GROUP_CONCAT(DISTINCT l.subscriberid)