我想在django中运行2个查询,我正在使用mysql,请帮帮我
第一个
SELECT * FROM `invitations`
WHERE post_id = 19215 GROUP BY (user_id)
它不是来自user_id的分组
data = Invitations.objects.filter(post_id=19215).annotate(user_id=Count('user_id'))
现在我增加了价值
data = Invitations.objects.values('user_id').filter(post_id=19215).annotate(user_id=Count('user_id'))
它返回我并非所有字段都选择*
data = Invitations.objects.values('user_id', 'xyz').filter(post_id=19215).annotate(user_id=Count('user_id'))
按user_id和xyz分组
请给我解决方案
,第二个是
SELECT *, GROUP_CONCAT(interview_mode) FROM invitations WHERE post_id = 19215 GROUP BY (user_id)
答案 0 :(得分:1)
运行:
query= "SELECT *, GROUP_CONCAT(interview_mode)
FROM invitations WHERE post_id = 19215
GROUP BY (user_id)"
data = Model.objects.raw(query)