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

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

    1. <tfoot id='nZ0au'></tfoot>

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

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

        当子查询没有用EXISTS引入时,select列表中只能指定一个表达式

        时间:2023-07-17

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

                  <tfoot id='sOP8i'></tfoot>

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

                  本文介绍了当子查询没有用EXISTS引入时,select列表中只能指定一个表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我的查询如下,其中包含一个子查询:

                  My query is as follows, and contains a subquery within it:

                   select count(distinct dNum)
                   from myDB.dbo.AQ
                   where A_ID in 
                    (SELECT DISTINCT TOP (0.1) PERCENT A_ID, 
                              COUNT(DISTINCT dNum) AS ud 
                   FROM         myDB.dbo.AQ
                   WHERE     M > 1 and B = 0 
                   GROUP BY A_ID ORDER BY ud DESC)
                  

                  我收到的错误是......

                  The error I am receiving is ...

                  Only one expression can be specified in the select list when the subquery is not
                  introduced with EXISTS.`
                  

                  当我单独运行子查询时,它返回得很好,所以我假设主查询有问题?

                  When I run the sub-query alone, it returns just fine, so I am assuming there is some issue with the main query?

                  推荐答案

                  WHERE A_ID IN (subquery)中不能返回两个(或多个)列在子查询中做比较子句 - 应该将 A_ID 与哪个列进行比较?您的子查询必须只返回与 IN 另一侧的列进行比较所需的一列.所以查询需要采用以下形式:

                  You can't return two (or multiple) columns in your subquery to do the comparison in the WHERE A_ID IN (subquery) clause - which column is it supposed to compare A_ID to? Your subquery must only return the one column needed for the comparison to the column on the other side of the IN. So the query needs to be of the form:

                  SELECT * From ThisTable WHERE ThisColumn IN (SELECT ThatColumn FROM ThatTable)
                  

                  您还想添加排序,以便您可以只从顶部的行中进行选择,但您不需要将 COUNT 作为列返回来进行排序;ORDER 子句中的排序与查询返回的列无关.

                  You also want to add sorting so you can select just from the top rows, but you don't need to return the COUNT as a column in order to do your sort; sorting in the ORDER clause is independent of the columns returned by the query.

                  试试这样的:

                  select count(distinct dNum) 
                  from myDB.dbo.AQ 
                  where A_ID in
                      (SELECT DISTINCT TOP (0.1) PERCENT A_ID
                      FROM myDB.dbo.AQ 
                      WHERE M > 1 and B = 0
                      GROUP BY A_ID 
                      ORDER BY COUNT(DISTINCT dNum) DESC)
                  

                  这篇关于当子查询没有用EXISTS引入时,select列表中只能指定一个表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:动态 SQL - EXEC(@SQL) 与 EXEC SP_EXECUTESQL(@SQL) 下一篇:SQL Server 中的连接组

                  相关文章

                • <small id='5X8gM'></small><noframes id='5X8gM'>

                  • <bdo id='5X8gM'></bdo><ul id='5X8gM'></ul>

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

                    <legend id='5X8gM'><style id='5X8gM'><dir id='5X8gM'><q id='5X8gM'></q></dir></style></legend>

                    <tfoot id='5X8gM'></tfoot>