pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

  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="kqauam0" 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="cgkeyik" 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="2wyaase" 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>

                          主站蜘蛛池模板: 北京乾茂兴业科技发展有限公司 | 电脑刺绣_绣花厂家_绣花章仔_织唛厂家-[源欣刺绣]潮牌刺绣打版定制绣花加工厂家 | 深圳活动策划公司|庆典策划|专业公关活动策划|深圳艺典文化传媒 重庆中专|职高|技校招生-重庆中专招生网 | [品牌官网]贵州遵义双宁口腔连锁_贵州遵义牙科医院哪家好_种植牙_牙齿矫正_原华美口腔 | 影视模板素材_原创专业影视实拍视频素材-8k像素素材网 | 国标白水泥,高标号白水泥,白水泥厂家-淄博华雪建材有限公司 | 压砖机、液压制砖机、静压砖机、环保砖机生产厂家—杜甫机械 | 不锈钢水箱生产厂家_消防水箱生产厂家-河南联固供水设备有限公司 | 泵阀展|阀门展|水泵展|流体机械展 -2025上海国际泵管阀展览会flowtech china | 天津散热器_天津暖气片_天津安尼威尔散热器制造有限公司 | 节流截止放空阀-不锈钢阀门-气动|电动截止阀-鸿华阀门有限公司 | 企业管理培训,企业培训公开课,企业内训课程,企业培训师 - 名课堂企业管理培训网 | 金属管浮子流量计_金属转子流量计厂家-淮安润中仪表科技有限公司 | IHDW_TOSOKU_NEMICON_EHDW系列电子手轮,HC1系列电子手轮-上海莆林电子设备有限公司 | 杭州公司变更法人-代理记账收费价格-公司注销代办_杭州福道财务管理咨询有限公司 | 环讯传媒,永康网络公司,永康网站建设,永康小程序开发制作,永康网站制作,武义网页设计,金华地区网站SEO优化推广 - 永康市环讯电子商务有限公司 | 网优资讯-为循环资源、大宗商品、工业服务提供资讯与行情分析的数据服务平台 | 防勒索软件_数据防泄密_Trellix(原McAfee)核心代理商_Trellix(原Fireeye)售后-广州文智信息科技有限公司 | 闪电优家-卫生间防水补漏_酒店漏水渗水维修_防水堵漏公司 | 华禹护栏|锌钢护栏_阳台护栏_护栏厂家-华禹专注阳台护栏、楼梯栏杆、百叶窗、空调架、基坑护栏、道路护栏等锌钢护栏产品的生产销售。 | 精密机械零件加工_CNC加工_精密加工_数控车床加工_精密机械加工_机械零部件加工厂 | 蒸汽热收缩机_蒸汽发生器_塑封机_包膜机_封切收缩机_热收缩包装机_真空机_全自动打包机_捆扎机_封箱机-东莞市中堡智能科技有限公司 | 网带通过式抛丸机,,网带式打砂机,吊钩式,抛丸机,中山抛丸机生产厂家,江门抛丸机,佛山吊钩式,东莞抛丸机,中山市泰达自动化设备有限公司 | 篮球架_乒乓球台_足球门_校园_竞技体育器材_厂家_价格-沧州浩然体育器材有限公司 | 隧道窑炉,隧道窑炉厂家-山东艾瑶国际贸易 | 衬四氟_衬氟储罐_四氟储罐-无锡市氟瑞特防腐科技有限公司 | 富森高压水枪-柴油驱动-养殖场高压清洗机-山东龙腾环保科技有限公司 | 德州网站制作 - 网站建设设计 - seo排名优化 -「两山建站」 | 智能楼宇-楼宇自控系统-楼宇智能化-楼宇自动化-三水智能化 | 厌氧反应器,IC厌氧反应器,厌氧三相分离器-山东创博环保科技有限公司 | 手术室净化厂家_成都实验室装修公司_无尘车间施工单位_洁净室工程建设团队-四川华锐16年行业经验 | 全自动面膜机_面膜折叠机价格_面膜灌装机定制_高速折棉机厂家-深圳市益豪科技有限公司 | 常州企业采购平台_常州MRO采购公司_常州米孚机电设备有限公司 | 隧道风机_DWEX边墙风机_SDS射流风机-绍兴市上虞科瑞风机有限公司 | 液晶拼接屏厂家_拼接屏品牌_拼接屏价格_监控大屏—北京维康 | 欧盟ce检测认证_reach检测报告_第三方检测中心-深圳市威腾检验技术有限公司 | 土壤检测仪器_行星式球磨仪_土壤团粒分析仪厂家_山东莱恩德智能科技有限公司 | ORP控制器_ORP电极价格-上优泰百科 | 专注提供国外机电设备及配件-工业控制领域一站式服务商-深圳市华联欧国际贸易有限公司 | 智能监控-安防监控-监控系统安装-弱电工程公司_成都万全电子 | 铝合金脚手架厂家-专注高空作业平台-深圳腾达安全科技 |