gpt4 book ai didi

mysql查询根据时间戳排列四个表中的数据

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

我正在尝试从四个表中获取有关“类型”的数据。类型可以是评论、封面图片更改、 friend 请求接受等。但问题是我所做的查询无法通过重复所有类型和时间戳来工作。我提出的查询是

SELECT c.up_date, c.user_id, c.id, f.id,
f.up_date, f.friend1, f.friend2, f.status,
s.postdate, s.status, s.id, s.display_name, s.userid, s.userid1, s.type,
c.type, f.type
FROM cover_pic c, wp_userstatus s, wp_friends f
WHERE s.userid = f.friend1
AND s.userid = c.user_id
AND f.status =3
AND c.user_id =4
ORDER BY s.postdate
LIMIT 0 , 30

任何人都可以帮助我根据时间戳和类型进行正确的查询

这是它给我的结果

enter image description here

我想要什么

timestamp userid_id id display_name type

233232323 1 1 paramveer comment

1212121212 1 2 paramveer coverpic

最佳答案

也许您想要一个联合连接

(select distinct s.postdate as postdate, s.userid, c.id, c.type
from wp_userstatus s
join cover_pic c on s.userid = c.user_id)
union
(select distinct s.postdate, s.userid, f.id, f.type
from wp_userstatus s
join wp_friends f on s.userid = f.friend1)
order by postdate
limit 30

这真的很难说。

关于mysql查询根据时间戳排列四个表中的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13431914/

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