私はvBulletinフォーラムに取り組んでいます。アイデアは、管理者が最新の投稿をすべて照会して「読んだ」ので、「チェック済み」とマークされるウェブページを作成することです。where節のMySQLの計算結果?
ウェブページは完璧に機能しますが、毎日新しい投稿が数千件あり、過去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
のみに未チェックの記事を取得し、私は私の最初のソリューションだけで
AND thread.lastpost-threadread.readtime > 0
を追加しました
thread.lastpost-threadread.readtime > 0
を計算する必要がありますwhere句に渡します。しかし、これはthreadread.userid = 90122
なくthreadread.threadid = thread.threadid
だから私の考えは
SELECT ... thread.lastpost-threadread.readtime AS isread
、その後AND isread > 0
を行うことでしたを選択するだけに
LEFT JOIN threadread AS threadread ON (threadread.threadid = thread.threadid AND threadread.userid = 90122)
を引き起こしました。これは、エラーが返さ
不明な列「isread」
私が最も可能性の高い非常に愚かな何かをしようとしているか、またはこのentiryクエリが動作しているか、単に理解していないが、私はアウトです私の問題を解決する方法に関するアイデアだから私は皆さんにお尋ねします:)
いくつかのサンプルデータは素晴らしいでしょう。私はあなたの質問に従うことができませんでした。 –
@TimBiegeleisenここにフィドルがあります:http://sqlfiddle.com/#!9/7dd95 – icecub