2016-09-22 66 views
0

我們已經升級了MYSQL數據庫;MYSQL升級GROUP BY子句;這是不符合sql_mode = only_full_group_by

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

試試這個:

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)
+0

謝謝,我會盡力的。爲什麼我的選擇適用於v5.6而不是5.7? – mbrc

+0

@mbrc。 。 。這不起作用的原因是由於SQL模式。 –

+0

我可以只爲sql 5.7啓用sql模式嗎? – mbrc