gpt4 book ai didi

php - Mysql 比较行之间的嵌套数据

转载 作者:行者123 更新时间:2023-11-29 17:57:12 25 4
gpt4 key购买 nike

我有一个包含多个数据的表。基本上有很多记录,每条记录都包含一个 uniqueid、postid、posttype 和排名:

sample data

现在我对 posttype=1 的 postid 感兴趣,并且排名比 posttype=2 的相同 postid 大基本上:

select * from data where postid=254454 and posttype=1 and rank > same post id but posttype=2 and smaller rank

希望我清楚任何帮助,谢谢

最佳答案

您必须在同一个表上进行联接以检查您的条件,然后选择第二个 (d2)。

select d2.* 
from data d1
inner join data d2 on d2.postid=d1.postid and d2.posttype=2 and d2.rank<d1.rank
where d1.postid=254454 and d1.posttype=1;

输出:

+----------+--------+----------+------+
| uniqueid | postid | posttype | rank |
+----------+--------+----------+------+
| 2 | 254454 | 2 | 2 |
+----------+--------+----------+------+

关于php - Mysql 比较行之间的嵌套数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48694001/

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