嗨,这是我的查询-如果我运行这个,我会得到多个客户id,但我只想选择一个客户id
SELECT payments.customer_id,
payments.reason,
payments.date
FROM payments
WHERE reason like '%error%'
ORDER BY payments.date DESC
如果我试图通过使用组,这是我收到的错误消息
Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'reason' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by (errno 1055) (sqlstate 42000)
您需要以下内容吗-
SELECT p.customer_id,
p.reason,
MAX(p.date) max_date
FROM payments p
WHERE p.reason like '%error%'
GROUP BY p.customer_id,
p.reason
ORDER BY max_date DESC
SELECT DISTINCT payments.customer_id,
payments.reason,
payments.date FROM payments
WHERE reason like '%error%'
ORDER BY payments.date DESC
DISTINCT将为您解决