我 google 了快 1 个小时了,实在找不出答案。 谢谢了。
SELECT t.*,
tt.tag_name,
CASE WHEN COUNT(c.tutorial_id) > 0 THEN TRUE ELSE FALSE END AS collected,
CASE WHEN COUNT(l.tutorial_id) > 0 THEN TRUE ELSE FALSE END AS liked,
COUNT(lc.tutorial_id) as likecount
FROM
tutorials t
LEFT JOIN
collections c ON t.tutorial_id = c.tutorial_id AND c.user_id = 'ec02a580-f9cd-4941-94c4-13a0c86246e3'
LEFT JOIN
likes l ON t.tutorial_id = l.tutorial_id AND l.user_id = 'ec02a580-f9cd-4941-94c4-13a0c86246e3'
LEFT JOIN
likes lc ON t.tutorial_id = lc.tutorial_id
LEFT JOIN
tutorials_tags tt on t.tutorial_id = tt.tutorial_id
WHERE
t.tutorial_id = '78e76b5b-9699-47a4-9c41-2c2f1cfb4059'
GROUP BY 1
ERROR: column "tt.tag_name" must appear in the GROUP BY clause or be used in an aggregate function
query 从表 like 里数这个 tutorial_id 有多少 like 和用户是否喜欢, 从 collections 查用户是否已经收藏, 从 tag 里查 tag_name. 我卡在 tag_name 不能 group by.
麻烦了!
SELECT t.*,
tt.tag_name,
CASE WHEN COUNT(c.tutorial_id) > 0 THEN TRUE ELSE FALSE END AS collected,
CASE WHEN COUNT(l.tutorial_id) > 0 THEN TRUE ELSE FALSE END AS liked,
COUNT(lc.tutorial_id) as likecount
FROM
tutorials t
LEFT JOIN
collections c ON t.tutorial_id = c.tutorial_id AND c.user_id = 'ec02a580-f9cd-4941-94c4-13a0c86246e3'
LEFT JOIN
likes l ON t.tutorial_id = l.tutorial_id AND l.user_id = 'ec02a580-f9cd-4941-94c4-13a0c86246e3'
LEFT JOIN
likes lc ON t.tutorial_id = lc.tutorial_id
LEFT JOIN
tutorials_tags tt on t.tutorial_id = tt.tutorial_id
WHERE
t.tutorial_id = '78e76b5b-9699-47a4-9c41-2c2f1cfb4059'
GROUP BY 1
ERROR: column "tt.tag_name" must appear in the GROUP BY clause or be used in an aggregate function
query 从表 like 里数这个 tutorial_id 有多少 like 和用户是否喜欢, 从 collections 查用户是否已经收藏, 从 tag 里查 tag_name. 我卡在 tag_name 不能 group by.
麻烦了!