<bdo id='WXRFA'></bdo><ul id='WXRFA'></ul>

  1. <i id='WXRFA'><tr id='WXRFA'><dt id='WXRFA'><q id='WXRFA'><span id='WXRFA'><b id='WXRFA'><form id='WXRFA'><ins id='WXRFA'></ins><ul id='WXRFA'></ul><sub id='WXRFA'></sub></form><legend id='WXRFA'></legend><bdo id='WXRFA'><pre id='WXRFA'><center id='WXRFA'></center></pre></bdo></b><th id='WXRFA'></th></span></q></dt></tr></i><div id='WXRFA'><tfoot id='WXRFA'></tfoot><dl id='WXRFA'><fieldset id='WXRFA'></fieldset></dl></div>
    <legend id='WXRFA'><style id='WXRFA'><dir id='WXRFA'><q id='WXRFA'></q></dir></style></legend>
  2. <small id='WXRFA'></small><noframes id='WXRFA'>

  3. <tfoot id='WXRFA'></tfoot>

      mySQL 查询键值对

      时间:2023-06-06
      <legend id='x0pgc'><style id='x0pgc'><dir id='x0pgc'><q id='x0pgc'></q></dir></style></legend>

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

              <bdo id='x0pgc'></bdo><ul id='x0pgc'></ul>
            • <tfoot id='x0pgc'></tfoot>

                <tbody id='x0pgc'></tbody>
              <i id='x0pgc'><tr id='x0pgc'><dt id='x0pgc'><q id='x0pgc'><span id='x0pgc'><b id='x0pgc'><form id='x0pgc'><ins id='x0pgc'></ins><ul id='x0pgc'></ul><sub id='x0pgc'></sub></form><legend id='x0pgc'></legend><bdo id='x0pgc'><pre id='x0pgc'><center id='x0pgc'></center></pre></bdo></b><th id='x0pgc'></th></span></q></dt></tr></i><div id='x0pgc'><tfoot id='x0pgc'></tfoot><dl id='x0pgc'><fieldset id='x0pgc'></fieldset></dl></div>
                本文介绍了mySQL 查询键值对的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                限时送ChatGPT账号..

                我正在对 wordpress 表 (postmeta) 进行查询.该表有键和值,我需要一个查询来获取所有匹配key1"等于value1"和key2"等于value2"的行,按value2排序

                I am doing a query on a wordpress table (postmeta). The table has keys and values and I need a query that will get all rows that match "key1" equal to "value1" and "key2" equal to "value2" ordered by value2

                该表基本上有 id、postid、key 和 value 列.

                The table basically has an id, postid, key and value columns.

                我什至不知道从哪里开始.我可以找到一个很好的值,即 ... where key='featured' &值=真.但我需要按行的值排序的前 25 个,其中 key='hits' 意味着我需要这些特色行的相应命中键的值

                I am not sure even where to start. I can find one value fine ie ... where key='featured' & value=true. But I need the top 25 ordered by the value of the rows where key='hits' meaning I need the value of the corresponding hits key for those featured rows

                我不知道该怎么做.

                TIA

                推荐答案

                根据您提供的有限详细信息,很难确切说明如何执行此操作.但是当您想返回键/值对时,您可以使用以下方法.

                It is difficult to say exactly how to do this with the limited details that you provided. But when you want to return key/value pairs you can use the following.

                您可以多次加入您的桌子:

                You can join on your table multiple times:

                select p1.postid,
                  p1.value Featured,
                  p2.value Hits
                from postmeta p1
                left join postmeta p2
                  on p1.postid = p2.postid
                  and p2.key = 'hits'
                where p1.key ='featured';
                

                参见SQL Fiddle with Demo

                或者你可以使用带有 CASE 表达式的聚合函数(使用 sum() 假设一个数值,你可以使用 max()/min() 用于字符串值:

                Or you can use an aggregate function with a CASE expression (using sum() assumes a numeric value, you can use max()/min() for string values:

                select postid,
                  sum(case when `key` = 'featured' then value end) Featured,
                  sum(case when `key` = 'hits' then value end) Hits
                from postmeta
                group by postid
                

                参见SQL Fiddle with Demo

                这篇关于mySQL 查询键值对的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:MySQL查询以根据自定义列名和值获取值 下一篇:编写 mysql 查询的想法

                相关文章

                最新文章

                    <tfoot id='BuwGL'></tfoot>
                  1. <i id='BuwGL'><tr id='BuwGL'><dt id='BuwGL'><q id='BuwGL'><span id='BuwGL'><b id='BuwGL'><form id='BuwGL'><ins id='BuwGL'></ins><ul id='BuwGL'></ul><sub id='BuwGL'></sub></form><legend id='BuwGL'></legend><bdo id='BuwGL'><pre id='BuwGL'><center id='BuwGL'></center></pre></bdo></b><th id='BuwGL'></th></span></q></dt></tr></i><div id='BuwGL'><tfoot id='BuwGL'></tfoot><dl id='BuwGL'><fieldset id='BuwGL'></fieldset></dl></div>
                    <legend id='BuwGL'><style id='BuwGL'><dir id='BuwGL'><q id='BuwGL'></q></dir></style></legend>

                      <bdo id='BuwGL'></bdo><ul id='BuwGL'></ul>

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