除了从与帖子相关的评论中获取最大日期之外,我的查询工作正常。
所以我想做的是:
非常感谢任何帮助。
查询无法获取最新的最新评论日期并按最新的
排序SELECT DISTINCT wallposts.p_id,wallposts.type,wallposts.value,wallposts.media,wallposts.youtube,wallposts.post_type,wallposts.tagedpersons,wallposts.title AS thetitle,wallposts.url,wallposts.description,wallposts.cur_image,wallposts.uip,wallposts.likes,wallposts.userid,wallposts.posted_by,wallposts.post as postdata,wallusers.*, UNIX_TIMESTAMP() - wallposts.date_created AS TimeSpent,wallposts.date_created,wallposts.course
FROM wallposts,wallusers
where (
wallposts.userid =4276 OR
wallposts.tagedpersons LIKE '%4276%' OR
EXISTS (SELECT * FROM wallcomments WHERE wallposts.p_id = wallcomments.post_id AND wallcomments.tagedpersons LIKE '%4276%')
)
AND wallusers.mem_id = wallposts.userid
order by wallposts.p_id desc
我试图解决问题的那个但是失败了:
SELECT DISTINCT wallposts.p_id,wallposts.type,wallposts.value,wallposts.media,wallposts.youtube,wallposts.post_type,wallposts.tagedpersons,wallposts.title AS thetitle,wallposts.url,wallposts.description,wallposts.cur_image,wallposts.uip,wallposts.likes,wallposts.userid,wallposts.posted_by,wallposts.post as postdata,wallusers.*, UNIX_TIMESTAMP() - wallposts.date_created AS TimeSpent,wallposts.date_created,wallposts.course
FROM wallposts,wallusers
JOIN wallusers wu on wallposts.userid = wu.mem_id
LEFT JOIN wallcomments wc ON wc.post_id(SELECT date_created as commentdate_created, UNIX_TIMESTAMP() - max(date_created) as latestcomment
FROM wallcomments wc WHERE wallposts.p_id = wc.post_id LIMIT 1)
where (
wallposts.userid = 4276 OR
wallposts.tagedpersons LIKE '%4276%' OR
EXISTS (SELECT * FROM wallcomments WHERE wallposts.p_id = wallcomments.post_id AND wallcomments.tagedpersons LIKE '%4276%')
)
order by greatest(latestcomment, TimeSpent) DESC
答案 0 :(得分:0)
查询本身对我来说有点奇怪 - LEFT JOIN似乎已损坏,请再次检查:
SELECT
DISTINCT wallposts.p_id,
wallposts.type,
wallposts.value,
wallposts.media,
wallposts.youtube,
wallposts.post_type,
wallposts.tagedpersons,
wallposts.title AS thetitle,
wallposts.url,
wallposts.description,
wallposts.cur_image,
wallposts.uip,
wallposts.likes,
wallposts.userid,
wallposts.posted_by,
wallposts.post as postdata,
wallusers.*,
UNIX_TIMESTAMP() - wallposts.date_created AS TimeSpent,
wallposts.date_created,
wallposts.course
FROM wallposts, wallusers
JOIN wallusers wu
on wallposts.userid = wu.mem_id
LEFT JOIN wallcomments wc
ON wc.post_id (
SELECT
date_created as commentdate_created,
UNIX_TIMESTAMP() - max(date_created) as latestcomment
FROM wallcomments wc
WHERE wallposts.p_id = wc.post_id LIMIT 1
)
WHERE (
wallposts.userid = 4276 OR
wallposts.tagedpersons LIKE '%4276%' OR
EXISTS (
SELECT *
FROM wallcomments
WHERE wallposts.p_id = wallcomments.post_id
AND wallcomments.tagedpersons LIKE '%4276%'
)
)
order by greatest(latestcomment, TimeSpent) DESC