这是我的查询:
SELECT messages.*,
units.*,
MAX(messages.created_at) AS 'conversation_date',
(select count(*) as messages from messages where unit_id = units.id),
WEEKOFYEAR(MAX(messages.created_at)) as 'woy',
YEAR(MAX(messages.created_at)) as 'year',
classifications.description AS 'classification'
FROM messages
JOIN units ON units.id = messages.unit_id
JOIN classifications ON units.classification_id = classifications.id
WHERE from_id <> units.creator_id GROUP BY messages.unit_id, from_id, to_id
我正在尝试命名第 4 列"messages"
,但名称按字面意思返回"(select count(*) as messages from messages where unit_id = units.id)"
我究竟做错了什么?