gpt4 book ai didi

mysql - 使用 MySQL 查询问答网站中用户首次回答的数量

转载 作者:行者123 更新时间:2023-11-29 09:16:04 25 4
gpt4 key购买 nike

我在为此编写查询时遇到问题。我有一个问答网站,我想找出用户首先回答的数量 - 对于用户回答的所有问题,哪些答案是特定问题的第一个答案。

我有两张 table -

  • 问题 - ID、问题
  • 答案 - ID、question_id、answering_userid、日期

我将其分为两个步骤

  1. 找出用户的答案
    • 从答案中选择 ID,其中answering_userid =“ABC”
  2. 看看他们是否是第一个
    • >????这就是我遇到问题的地方。我认为它将使用 MIN(date)。

有人可以帮助我实现这个吗?

问候

最佳答案

你可能想要这样的东西:


select a.id, a.answering_userid
from answers a
inner join (
select answering_userid, question_id, min(date) as mindate
from answers
group by answering_userid, question_id
) first on a.question_id = first.question_id
and a.date = first.mindate
and a.answering_userid = first.answering_userid

请注意,如果您在同一时刻有 2 个答案,这将返回重复的结果。此外,这完全未经测试。

关于mysql - 使用 MySQL 查询问答网站中用户首次回答的数量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4180989/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com