gpt4 book ai didi

mysql - 将限制传递给 mysql 中的 "in"查询

转载 作者:行者123 更新时间:2023-11-29 02:57:48 24 4
gpt4 key购买 nike

我的表是这样的: enter image description here

现在我想通过特定 voices_id 的限制。

我的意思是,如果我只想要 3 个特定 voices_id 的记录,那么该怎么做? (voices_id=153 和 154 的 3 条记录)在哪里通过限制?

最佳答案

这是你能做的

select *
from table_name t1
where t1.voices_id in (153,154)
and
(
select count(*) from table_name t2
where t1.voices_id = t2.voices_id and t1.id <= t2.id
) <= 3
order by t1.voices_id
;

这里是条件t1.id <= t2.id将为您提供每组的最后 3 个条目,您可以将其反转为前 3 个条目。

关于mysql - 将限制传递给 mysql 中的 "in"查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28582538/

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