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="xxrh7l5" 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="xfvppr7" 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="zxdndbj" 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>

                          主站蜘蛛池模板: 泰来华顿液氮罐,美国MVE液氮罐,自增压液氮罐,定制液氮生物容器,进口杜瓦瓶-上海京灿精密机械有限公司 | 杭州营业执照代办-公司变更价格-许可证办理流程_杭州福道财务管理咨询有限公司 | B2B网站_B2B免费发布信息网站_B2B企业贸易平台 - 企资网 | 莱州网络公司|莱州网站建设|莱州网站优化|莱州阿里巴巴-莱州唯佳网络科技有限公司 | 塑料检查井_双扣聚氯乙烯增强管_双壁波纹管-河南中盈塑料制品有限公司 | 薄壁轴承-等截面薄壁轴承生产厂家-洛阳薄壁精密轴承有限公司 | 仿真茅草_人造茅草瓦价格_仿真茅草厂家_仿真茅草供应-深圳市科佰工贸有限公司 | 健康管理师报名入口,2025年健康管理师考试时间信息网-网站首页 塑料造粒机「厂家直销」-莱州鑫瑞迪机械有限公司 | 爱佩恒温恒湿测试箱|高低温实验箱|高低温冲击试验箱|冷热冲击试验箱-您身边的模拟环境试验设备技术专家-合作热线:400-6727-800-广东爱佩试验设备有限公司 | 常州翔天实验仪器厂-恒温振荡器-台式恒温振荡器-微量血液离心机 恒温恒湿箱(药品/保健品/食品/半导体/细菌)-兰贝石(北京)科技有限公司 | 铁盒_铁罐_马口铁盒_马口铁罐_铁盒生产厂家-广州博新制罐 | 高低温试验房-深圳高低温湿热箱-小型高低温冲击试验箱-爱佩试验设备 | 压装机-卧式轴承轮轴数控伺服压装机厂家[铭泽机械] | 常州减速机_减速机厂家_常州市减速机厂有限公司 | 大行程影像测量仪-探针型影像测量仪-增强型影像测量仪|首丰百科 大通天成企业资质代办_承装修试电力设施许可证_增值电信业务经营许可证_无人机运营合格证_广播电视节目制作许可证 | 快速门厂家批发_PVC快速卷帘门_高速门_高速卷帘门-广州万盛门业 快干水泥|桥梁伸缩缝止水胶|伸缩缝装置生产厂家-广东广航交通科技有限公司 | 青岛侦探_青岛侦探事务所_青岛劝退小三_青岛调查出轨取证公司_青岛婚外情取证-青岛探真调查事务所 | 无痕胶_可移胶_无痕双面胶带_可移无痕胶厂家-东莞凯峰 | 成都租车_成都租车公司_成都租车网_众行宝 | 全自动烧卖机厂家_饺子机_烧麦机价格_小笼汤包机_宁波江北阜欣食品机械有限公司 | 湖南印刷厂|长沙印刷公司|画册印刷|挂历印刷|台历印刷|杂志印刷-乐成印刷 | 选矿设备,选矿生产线,选矿工艺,选矿技术-昆明昆重矿山机械 | 南京欧陆电气股份有限公司-风力发电机官网| 上海办公室装修,写字楼装修—启鸣装饰设计工程有限公司 | 上海律师事务所_上海刑事律师免费咨询平台-煊宏律师事务所 | 信阳网站建设专家-信阳时代网联-【信阳网站建设百度推广优质服务提供商】信阳网站建设|信阳网络公司|信阳网络营销推广 | 玄米影院| 样品瓶(色谱样品瓶)百科-浙江哈迈科技有限公司 | 成都热收缩包装机_袖口式膜包机_高速塑封机价格_全自动封切机器_大型套膜机厂家 | 高硼硅玻璃|水位计玻璃板|光学三棱镜-邯郸奥维玻璃科技有限公司 高温高压釜(氢化反应釜)百科 | 临沂招聘网_人才市场_招聘信息_求职招聘找工作请认准【马头商标】 | 防堵吹扫装置-防堵风压测量装置-电动操作显示器-兴洲仪器 | 高低温老化试验机-步入式/低温恒温恒湿试验机-百科 | 工控机,嵌入式主板,工业主板,arm主板,图像采集卡,poe网卡,朗锐智科 | EDLC超级法拉电容器_LIC锂离子超级电容_超级电容模组_软包单体电容电池_轴向薄膜电力电容器_深圳佳名兴电容有限公司_JMX专注中高端品牌电容生产厂家 | 广东健伦体育发展有限公司-体育工程配套及销售运动器材的体育用品服务商 | 奇酷教育-Python培训|UI培训|WEB大前端培训|Unity3D培训|HTML5培训|人工智能培训|JAVA开发的教育品牌 | SMC-SMC电磁阀-日本SMC气缸-SMC气动元件展示网 | 四探针电阻率测试仪-振实密度仪-粉末流动性测定仪-宁波瑞柯微智能 | 便携式表面粗糙度仪-彩屏硬度计-分体式粗糙度仪-北京凯达科仪科技有限公司 | 臭氧发生器_臭氧消毒机 - 【同林品牌 实力厂家】 |