如何显示rowcount中行数为1或更多的所有记录?

时间:2015-10-28 14:25:21

标签: sql database ms-access ms-access-2013

我正在尝试获取计数中计数超过1的所有行。我可以从此查询中返回此数据:

SELECT Claims.PT_SSN, Claims.FROM_DATE, Count(Claims.FROM_DATE) AS [COUNT], Claims.PROC_CODE, Claims.CHARGE_AMT, Claims.UNITS, Count(Claims.FROM_DATE) AS COUNT_DATES INTO mue_errors
FROM Claims INNER JOIN mue_values ON Claims.PROC_CODE = mue_values.cpt_code
WHERE (((Claims.PROC_CODE)=[mue_values].[cpt_code]))
GROUP BY Claims.PT_SSN, Claims.FROM_DATE, Claims.PROC_CODE, Claims.CHARGE_AMT, Claims.UNITS, Claims.INEL_AMT_1
HAVING (((Claims.CHARGE_AMT)<>[INEL_AMT_1]) AND ((Count(Claims.FROM_DATE))>1));


PT_SSN      FROM_DATE COUNT PROC_CODE  CHARGE_AMT UNITS COUNT_DATES
406588032   1/17/2014   2   80053      $62.58       1     2
406588032   1/17/2014   2   80061      $144.93      1     2
406588032   1/17/2014   2   83036      $71.39       1     2

这是表格中正确的行数,但我想获得每个Proc_Code计算的两行中的每一行。

所以结果应该是:

PT_SSN      FROM_DATE    PROC_CODE CHARGE_AMT    UNITS  
406588032   1/17/2014       80053    $62.58        1   
406588032   1/17/2014       80053    $62.58        1   
406588032   1/17/2014       80061    $144.93       1    
406588032   1/17/2014       80061    $144.93       1   
406588032   1/17/2014       83036    $71.39        1   
406588032   1/17/2014       83036    $71.39        1   

1 个答案:

答案 0 :(得分:0)

如果您只想要重复的行,则可以使用union all并保持重复

SELECT *
FROM table1
UNION ALL
SELECT *
FROM table1