1. <small id='ddbdk'></small><noframes id='ddbdk'>

    2. <legend id='ddbdk'><style id='ddbdk'><dir id='ddbdk'><q id='ddbdk'></q></dir></style></legend>

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

        如果第一个 SELECT 返回 0 行,则第二个 SELECT 查询

        Second SELECT query if first SELECT returns 0 rows(如果第一个 SELECT 返回 0 行,则第二个 SELECT 查询)
          <legend id='sYvVb'><style id='sYvVb'><dir id='sYvVb'><q id='sYvVb'></q></dir></style></legend>

        • <small id='sYvVb'></small><noframes id='sYvVb'>

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

              • <bdo id='sYvVb'></bdo><ul id='sYvVb'></ul>
                  <tbody id='sYvVb'></tbody>
              • <tfoot id='sYvVb'></tfoot>
                  本文介绍了如果第一个 SELECT 返回 0 行,则第二个 SELECT 查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试加快 PHP 脚本的运行速度,目前我正在该事物的 Mysql 域中推送一些 PHP 逻辑.如果第一个 Select 不返回行或计数为零,是否有办法进行不同的选择查询?

                  I am trying to speed up a PHP script and I am currently pushing some PHP logic in the Mysql domain of the thing. Is there a way to make a different select query if the first Select returns no rows, or a count of zero ?

                  请记住,第一个查询需要先运行,第二个查询应该在第一个查询返回空集时激活.

                  Keeping in mind that the first query needs to run first, and the second should only be activated if the first one returns an empty set.

                  SELECT * FROM proxies WHERE (A='B') || SELECT * FROM proxies WHERE (A='C')
                  

                  对于上面的 2 个查询,我有这个代码,但它似乎每个查询运行两次(一次计数,一次返回).有没有更好的方法来做到这一点?

                  For the above 2 queries I have this code, but it seems to run each query twice (once to count, and once to return). Is there a better way to do this?

                  IF (SELECT count(*) FROM proxies WHERE A='B')>0
                      THEN SELECT * FROM proxies WHERE A='B'
                  ELSEIF (SELECT count(*) FROM proxies WHERE A='C')>0
                      THEN SELECT * FROM proxies WHERE A='C'
                  END IF
                  

                  推荐答案

                  一种选择是将 UNION ALLEXISTS 一起使用:

                  One option would be to use UNION ALL with EXISTS:

                  SELECT * 
                  FROM proxies 
                  WHERE A='B'
                  UNION ALL
                  SELECT * 
                  FROM proxies 
                  WHERE A='C' AND NOT EXISTS (
                      SELECT 1
                      FROM proxies 
                      WHERE A='B'
                  )
                  

                  • SQL Fiddle 演示
                  • 这将返回 proxies 表中的行,其中 A='B' 如果它们存在.但是,如果它们不存在,它将查找那些带有 A='C' 的行.

                    This will return rows from the proxies table where A='B' if they exist. However, if they don't exist, it will look for those rows with A='C'.

                    这篇关于如果第一个 SELECT 返回 0 行,则第二个 SELECT 查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                    本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  ibtmp1是非压缩的innodb临时表的独立表空间,通过innodb_temp_data_file_path参数指定文件的路径,文件名和大小,默认配置为ibtmp1:12M:autoextend,也就是说在文件系统磁盘足够的情况下,这个文件大小是可以无限增长的。 为了避免ibtmp1文件无止境的暴涨导致
                  SQL query to group by day(按天分组的 SQL 查询)
                  What does SQL clause quot;GROUP BY 1quot; mean?(SQL 子句“GROUP BY 1是什么意思?意思是?)
                  MySQL groupwise MAX() returns unexpected results(MySQL groupwise MAX() 返回意外结果)
                  MySQL SELECT most frequent by group(MySQL SELECT 按组最频繁)
                  Include missing months in Group By query(在 Group By 查询中包含缺失的月份)
                    <tfoot id='CTs6f'></tfoot>
                    • <bdo id='CTs6f'></bdo><ul id='CTs6f'></ul>
                      <legend id='CTs6f'><style id='CTs6f'><dir id='CTs6f'><q id='CTs6f'></q></dir></style></legend>
                      1. <i id='CTs6f'><tr id='CTs6f'><dt id='CTs6f'><q id='CTs6f'><span id='CTs6f'><b id='CTs6f'><form id='CTs6f'><ins id='CTs6f'></ins><ul id='CTs6f'></ul><sub id='CTs6f'></sub></form><legend id='CTs6f'></legend><bdo id='CTs6f'><pre id='CTs6f'><center id='CTs6f'></center></pre></bdo></b><th id='CTs6f'></th></span></q></dt></tr></i><div id='CTs6f'><tfoot id='CTs6f'></tfoot><dl id='CTs6f'><fieldset id='CTs6f'></fieldset></dl></div>
                        • <small id='CTs6f'></small><noframes id='CTs6f'>

                            <tbody id='CTs6f'></tbody>