SQL中的子查询/连接问题

时间:2014-02-15 15:03:02

标签: sql sql-server sql-server-2005

如何使用来自同一个表的子查询或连接将以下两个查询连接到一个查询。

select case#
from _CB_Orders
GROUP BY case#
HAVING COUNT (case#) >1;

select Distinct RFMS_Inv_Num, case#
from _CB_Orders

任何帮助..

2 个答案:

答案 0 :(得分:0)

这是你想要的吗?

select RFMS_Inv_Num, case#
from _CB_Orders
where RFMS_Inv_Num <> 'AETEST' and
      case# in (select case#
                from _CB_Orders
                GROUP BY case#
                HAVING COUNT(case#) > 1
               );

有关多次出现的案例的详细信息?

答案 1 :(得分:0)

据我了解,您正尝试按RFMS_Inv_Numcase#

进行分组
 select RFMS_Inv_Num,case#
 from _CB_Orders
 GROUP BY RFMS_Inv_Num, case#
 HAVING COUNT (*) >1;

如果不是,请编辑您的问题或评论