久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

  1. <legend id='4do0s'><style id='4do0s'><dir id='4do0s'><q id='4do0s'></q></dir></style></legend>
  2. <small id='4do0s'></small><noframes id='4do0s'>

    <i id='4do0s'><tr id='4do0s'><dt id='4do0s'><q id='4do0s'><span id='4do0s'><b id='4do0s'><form id='4do0s'><ins id='4do0s'></ins><ul id='4do0s'></ul><sub id='4do0s'></sub></form><legend id='4do0s'></legend><bdo id='4do0s'><pre id='4do0s'><center id='4do0s'></center></pre></bdo></b><th id='4do0s'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='4do0s'><tfoot id='4do0s'></tfoot><dl id='4do0s'><fieldset id='4do0s'></fieldset></dl></div>

  3. <tfoot id='4do0s'></tfoot>
      <bdo id='4do0s'></bdo><ul id='4do0s'></ul>

      編寫 mysql 查詢的想法

      Idea for writing a mysql query(編寫 mysql 查詢的想法)
          <tbody id='JFITV'></tbody>
        <legend id='JFITV'><style id='JFITV'><dir id='JFITV'><q id='JFITV'></q></dir></style></legend>
        • <bdo id='JFITV'></bdo><ul id='JFITV'></ul>

          <tfoot id='JFITV'></tfoot>
            <i id='JFITV'><tr id='JFITV'><dt id='JFITV'><q id='JFITV'><span id='JFITV'><b id='JFITV'><form id='JFITV'><ins id='JFITV'></ins><ul id='JFITV'></ul><sub id='JFITV'></sub></form><legend id='JFITV'></legend><bdo id='JFITV'><pre id='JFITV'><center id='JFITV'></center></pre></bdo></b><th id='JFITV'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='JFITV'><tfoot id='JFITV'></tfoot><dl id='JFITV'><fieldset id='JFITV'></fieldset></dl></div>

            <small id='JFITV'></small><noframes id='JFITV'>

                本文介紹了編寫 mysql 查詢的想法的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                限時送ChatGPT賬號..

                我有一個名為 wp_bp_activity 的表,其中包含許多列,我認為我應該使用其中的 4 個來解決這個問題:id, type、item_iddate_recorded.

                I've a table named wp_bp_activity with many columns that I think I should work with 4 of them for this issue: id, type, item_id and date_recorded.

                1 - 當有人發布新活動時,typeactivity_updateitem_id0

                1 - When someone post a new activity the type is activity_update and item_id is 0

                2 - 當有人對活動發表新評論時,其 typeactivity_comment 并且 item_id 存在id

                2 - When someone post a new comment on an activity its type is activity_comment and item_id is existed activity id in column id

                3 - 在兩者中,date_recorded 是插入數據的日期.

                3 - In both, date_recorded is the date of when data is inserted.

                表中還有更多type.

                但我只想獲取最近有人回復typeactivity_update的行是新的(基于date_recorded 我認為)

                But I wanna fetch only rows with type of activity_update that someone is recently replied to or are new (based on date_recorded I think)

                我試過的是:

                SELECT  a.*, b.*
                FROM wp_bp_activity as a, wp_bp_activity as b
                WHERE
                  ((b.type = 'activity_update') OR (b.type = 'activity_comment' AND b.item_id = a.id))
                order by cast(a.date_recorded as datetime) desc
                limit 0,20
                

                執行時間過長,并以內存不足錯誤結束.

                That takes too long to be executed and ends with memory insufficient error.

                對此類查詢的任何幫助表示贊賞.

                Any help on this kind of query is appreciated.

                更新 #1

                                        wp_bp_activity table
                
                    id              type             item_id         date_recorded
                |---------|-----------------------|-----------|--------------------------
                |  12081  |   activity_comment    |   12079   |    2013-10-18 07:27:01
                |---------|-----------------------|-----------|--------------------------
                |  12080  |   activity_update     |     0     |    2013-10-18 07:26:40
                |---------|-----------------------|-----------|--------------------------
                |  12079  |   activity_update     |     0     |    2013-10-17 05:15:43
                

                我想從這個表中得到哪些行是這些 id 的順序:

                12079
                12080
                

                我不想得到的:

                activity_comment 類型

                應該以什么順序獲取行?

                如您所見,activity_comment 類型的行有一個 item_id,其值為 12079.所以12079是最近有人評論它的最新活動,12080沒有評論只是發布.所以我想要兩個,但按這個順序:

                As you can see the row with activity_comment type has an item_id with the value of 12079. so 12079 is the latest activity that recently someone made a comment on it, and 12080 has no comments but is just posted. So I want both but at this order:

                12079
                12080
                

                推薦答案

                我假設您正在尋找最近的條目"(WHERE type = 'activity_update' AND date_recorded > [threshold]) 和具有最近回復的條目,無論條目的年齡如何"(WHERE reply.type = 'activity_comment' AND reply.date_recorded > [threshold]).

                I am going to assume that you are looking for "recent entries" (WHERE type = 'activity_update' AND date_recorded > [threshold]) and "entries having a recent reply, regardless of the entry's age" (WHERE reply.type = 'activity_comment' AND reply.date_recorded > [threshold]).

                第一組很簡單:

                SELECT entries.*
                FROM activity AS entries
                WHERE type = 'activity_update' AND date_recorded > [threshold]
                

                第二組不太明顯:

                SELECT entries.*
                FROM activity AS entries
                JOIN activity AS replies
                    ON replies.item_id = entries.id
                    AND replies.type = 'activity_comment'
                WHERE
                    entries.type = 'activity_update'
                    AND replies.date_recorded > [threshold]
                

                綜合起來:

                SELECT entries.*
                FROM activity AS entries
                LEFT JOIN activity AS replies -- LEFT JOIN, because an INNER JOIN would filter out entries without any reply
                    ON  replies.item_id = entries.id
                    AND replies.type = 'activity_comment'
                WHERE
                    entries.type = 'activity_update'
                    AND (
                        entries.date_recorded > [threshold]
                        OR replies.date_recorded > [threshold] -- evaluates as FALSE if replies.date_recorded is NULL
                    )
                ORDER BY IFNULL(replies.date_recorded, entries.date_recorded) -- replies if not null, entries otherwise
                

                我并不為我的 ORDER BY 子句表現不佳而自豪,我希望有人能提出更好的想法

                I am not proud of my poorly performing ORDER BY clause, I hope someone can suggest a better idea

                這篇關于編寫 mysql 查詢的想法的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                相關文檔推薦

                SQL query to get all products, categories and meta data woocommerce/wordpress(獲取所有產品、類別和元數據的 SQL 查詢 woocommerce/wordpress)
                Can I figure out a list of databases and the space used by SQL Server instances without writing SQL queries?(我可以在不編寫 SQL 查詢的情況下找出數據庫列表和 SQL Server 實例使用的空間嗎?) - IT屋-程序員軟件開發
                How to create a login to a SQL Server instance?(如何創建對 SQL Server 實例的登錄?)
                How to know the version and edition of SQL Server through registry search(如何通過注冊表搜索知道SQL Server的版本和版本)
                Why do I get a quot;data type conversion errorquot; with ExecuteNonQuery()?(為什么會出現“數據類型轉換錯誤?使用 ExecuteNonQuery()?)
                How to show an image from a DataGridView to a PictureBox?(如何將 DataGridView 中的圖像顯示到 PictureBox?)

                <small id='YGeTh'></small><noframes id='YGeTh'>

                <tfoot id='YGeTh'></tfoot>
              • <i id='YGeTh'><tr id='YGeTh'><dt id='YGeTh'><q id='YGeTh'><span id='YGeTh'><b id='YGeTh'><form id='YGeTh'><ins id='YGeTh'></ins><ul id='YGeTh'></ul><sub id='YGeTh'></sub></form><legend id='YGeTh'></legend><bdo id='YGeTh'><pre id='YGeTh'><center id='YGeTh'></center></pre></bdo></b><th id='YGeTh'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='YGeTh'><tfoot id='YGeTh'></tfoot><dl id='YGeTh'><fieldset id='YGeTh'></fieldset></dl></div>

                <legend id='YGeTh'><style id='YGeTh'><dir id='YGeTh'><q id='YGeTh'></q></dir></style></legend>
                  <bdo id='YGeTh'></bdo><ul id='YGeTh'></ul>
                        <tbody id='YGeTh'></tbody>

                          主站蜘蛛池模板: 视频第一区| 亚洲视频一区二区三区 | 欧美激情区 | 在线观看国产视频 | 亚洲日本免费 | 久久91精品国产 | 日日干干夜夜 | 日韩欧美在 | 国产精品性做久久久久久 | 看黄在线 | 国产电影一区二区三区爱妃记 | 五月激情综合 | 精品福利一区二区三区 | 三级黄色大片网站 | 超碰在线免费av | 91se在线| 黄视频在线网站 | www.色.com| 午夜小视频在线播放 | 国产成人亚洲精品 | 欧美激情a∨在线视频播放 成人免费共享视频 | 久久久久久久久久久久久91 | 日韩性生活网 | 欧美韩一区二区三区 | 国产三级电影网站 | 成人亚洲精品久久久久软件 | 欧美日韩国产综合在线 | 国产精品视频免费观看 | 精品国产91 | 国产日韩一区二区 | 五月香婷婷 | 国产精品精品 | 本地毛片 | 一区视频 | 日韩精品在线免费观看视频 | 中文精品一区二区 | 在线观看国产wwwa级羞羞视频 | 国产专区在线 | 黄片毛片免费观看 | 午夜av成人 | 人人射人人草 |