<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 并按特定选择排序?

        SQL: how to use UNION and order by a specific select?(SQL:如何使用 UNION 并按特定选择排序?)
            <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 并按特定选择排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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 查询中包含缺失的月份)

                      <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>
                              <tbody id='0vY6I'></tbody>
                          1. <small id='0vY6I'></small><noframes id='0vY6I'>