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

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

  • <legend id='S1dnD'><style id='S1dnD'><dir id='S1dnD'><q id='S1dnD'></q></dir></style></legend>

        <tfoot id='S1dnD'></tfoot>

        SQL:如何使用 UNION 并按特定选择排序?

        时间:2023-10-08
            <tbody id='WfmA3'></tbody>
          <tfoot id='WfmA3'></tfoot>
            <i id='WfmA3'><tr id='WfmA3'><dt id='WfmA3'><q id='WfmA3'><span id='WfmA3'><b id='WfmA3'><form id='WfmA3'><ins id='WfmA3'></ins><ul id='WfmA3'></ul><sub id='WfmA3'></sub></form><legend id='WfmA3'></legend><bdo id='WfmA3'><pre id='WfmA3'><center id='WfmA3'></center></pre></bdo></b><th id='WfmA3'></th></span></q></dt></tr></i><div id='WfmA3'><tfoot id='WfmA3'></tfoot><dl id='WfmA3'><fieldset id='WfmA3'></fieldset></dl></div>
              <bdo id='WfmA3'></bdo><ul id='WfmA3'></ul>

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

              2. <legend id='WfmA3'><style id='WfmA3'><dir id='WfmA3'><q id='WfmA3'></q></dir></style></legend>
                  本文介绍了SQL:如何使用 UNION 并按特定选择排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有两个选择:

                  SELECT id FROM a -- returns 1,4,2,3
                  UNION
                  SELECT id FROM b -- returns 2,1
                  

                  我收到正确的行数,例如:1,4,2,3.

                  I'm receiving correct num of rows, like: 1,4,2,3.

                  但我首先想要b 表结果:2,1,4,32,1,3,4

                  But I want b table results first: 2,1,4,3 or 2,1,3,4

                  我该怎么做?

                  (我使用的是 Oracle)

                  (I'm using Oracle)

                  推荐答案

                  使用@Adrian 提示,我找到了解决方案:

                  Using @Adrian tips, I found a solution:

                  我正在使用 GROUP BYCOUNT.我尝试将 DISTINCTORDER BY 一起使用,但收到错误消息:not a SELECTed expression"

                  I'm using GROUP BY and COUNT. I tried to use DISTINCT with ORDER BY but I'm getting error message: "not a SELECTed expression"

                  select id from 
                  (
                      SELECT id FROM a -- returns 1,4,2,3
                      UNION ALL -- changed to ALL
                      SELECT id FROM b -- returns 2,1
                  )
                  GROUP BY id ORDER BY count(id);
                  

                  感谢 Adrian 和这个博客.

                  Thanks Adrian and this blog.

                  这篇关于SQL:如何使用 UNION 并按特定选择排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:MySQL - 如果它以数字或特殊字符开头 下一篇:SQLite SELECT 特定月份的日期

                  相关文章

                  <legend id='0vY6I'><style id='0vY6I'><dir id='0vY6I'><q id='0vY6I'></q></dir></style></legend>

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