我正在研究vBulletin论坛。这个想法是创建一个网页,管理员可以查询所有最新帖子并“读取”它们,以便将它们标记为“已检查”。Mysql计算结果在where子句中?
该网页的工作原理非常好,但是,查询速度有点慢,因为我们每天都会收到新帖子的贴子,现在它正在拉取过去24小时的所有帖子。
要解决这个问题,我希望它只拉取未检查的帖子。
原始查询如下:
SELECT
thread.forumid, thread.firstpostid, thread.lastpost, thread.lastposter, thread.lastpostid, thread.replycount,
thread.threadid, thread.title, thread.open, thread.views, post.pagetext AS preview, post.userid AS lastpuserid, threadread.readtime AS readtime, threadread.userid AS userid
FROM thread AS thread
LEFT JOIN deletionlog AS deletionlog ON (thread.threadid = deletionlog.primaryid AND deletionlog.type = 'thread')
LEFT JOIN post AS post ON (post.postid = thread.lastpostid)
LEFT JOIN threadread AS threadread ON (threadread.threadid = thread.threadid AND threadread.userid = 90122)
WHERE open <> 10
AND thread.lastpost >= 1494100000
AND thread.forumid NOT IN(0013482730313233343537)
AND thread.visible = '1'
AND post.visible = 1
AND deletionlog.primaryid IS NULL
GROUP BY thread.threadid
ORDER BY thread.lastpost DESC
只获取选中的帖子,我需要计算
thread.lastpost-threadread.readtime > 0
我的第一个解决方案是只需添加
AND thread.lastpost-threadread.readtime > 0
到where子句。然而,这引起了
LEFT JOIN threadread AS threadread ON (threadread.threadid = thread.threadid AND threadread.userid = 90122)
,只选择threadread.userid = 90122
,而不是threadread.threadid = thread.threadid
所以我的想法是做
SELECT ... thread.lastpost-threadread.readtime AS isread
,然后AND isread > 0
。这返回的错误
未知列“isread”
我最有可能试图做一些事情非常愚蠢的或根本不明白这是如何entiry查询工作,但我出来关于如何解决我的问题的想法。所以现在我问你们:)
一些示例数据会很好。我无法遵循你的问题。 –
@TimBiegeleisen这是小提琴:http://sqlfiddle.com/#!9/7dd95 – icecub