久久久久久久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, typeitem_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>

                          主站蜘蛛池模板: 中文字幕第一页在线 | 午夜精品一区二区三区在线播放 | 日韩另类 | 一级看片免费视频 | 在线免费毛片 | 亚洲欧美在线观看 | 婷婷在线视频 | 日韩av在线一区 | 一区二区精品 | 亚洲精品综合一区二区 | 国产福利在线 | 99精品国产一区二区青青牛奶 | 国产精品久久久久无码av | 精品粉嫩aⅴ一区二区三区四区 | 涩涩视频网站在线观看 | 欧美一级二级视频 | 美女网站视频免费黄 | 欧美一级免费片 | 99精品视频免费观看 | 久草在线免费资源 | 欧美一级视频免费看 | 日本一区二区三区四区 | 欧美在线一区视频 | 中文字幕欧美一区二区 | 亚洲综合在线播放 | 韩国欧洲一级毛片 | 久久91精品久久久久久9鸭 | 在线观看欧美一区 | 亚洲视频 欧美视频 | 亚洲高清免费视频 | 色综合天天天天做夜夜夜夜做 | 四虎影院免费在线播放 | 午夜久久久 | 欧美亚洲视频 | 亚洲一区二区三区四区五区午夜 | 欧美狠狠操 | 国产精品一区二区不卡 | 久久美女网 | 99热这里都是精品 | www.jizzjizz| 99国产精品一区二区三区 |