访问 sql groupby

Access sql groupby

我有一张桌子1

 pbsc   qty   wt

 pbsc1   1    0  
 pbsc2   2    10
 pbsc3   1    0
 pbsc2   2    9    
 pbsc1   0    8
 pbsc4   9    9

我正在尝试从表 1 中获取 2 个结果集(2 个查询表)

如果 pbsc 有相似的数据,求和 qty 和 wt,对于我使用的那个查询

SELECT Table1.pbsc, sum(Table1.qty) As quantity , sum(Table1.wt) As
> Weight
>       FROM Table1 group by Table1.pbsc;

这给了我

pbsc    quantity    Weight
pbsc1   1             8
pbsc2   4            19
pbsc3   1             0
pbsc4   9             9

但我试图仅将 pbsc1、pbsc2 作为一个结果集,因为它们在 Table1 中出现不止一次,如 result1

  pbsc    qty    wt
  pbsc1     1     8
  pbsc2     4     19

result2 应该是这样的(因为 pbsc3、pbsc4 只出现一次)

  pbsc   qty   wt
  pbsc3   1    0
  pbsc4   9    9

--不止一个pbsc.

SELECT Table1.pbsc,
       sum(Table1.qty) As quantity ,
       sum(Table1.wt) As  Weight
  FROM Table1
 group by Table1.pbsc
 having count(*) > 1;

--pbsc只有一条记录

SELECT Table1.pbsc,
       sum(Table1.qty) As quantity ,
       sum(Table1.wt) As  Weight
  FROM Table1
 group by Table1.pbsc
 having count(*) = 1;
SELECT Table1.pbsc,
       SUM(Table1.qty) AS Quantity,
       SUM(Table1.wt) AS  Weight
FROM Table1
WHERE Table1.pbsc IN (psc1, pbsc2)
GROUP BY Table1.pbsc

SELECT Table1.pbsc,
       SUM(Table1.qty) AS quantity,
       SUM(Table1.wt) AS  Weight
FROM Table1
WHERE Table1.pbsc IN (psc3, pbsc4)
GROUP BY Table1.pbsc