简体   繁体   English

获取总行数

[英]Getting row count total

Currently, I've got three columns of lot data.目前,我有三列批次数据。 Each lot has common value set with different date stamps.每批都有不同的日期戳设置的共同价值。 I'm trying to get a count of the groupings per the common value set.我正在尝试计算每个公共值集的分组数。 example below: Table name = Data1下面的示例:表名 = Data1

 Position     Lot       Date                      
    1         ABCD       2021-10-01 15:00.000
    1         ABCD       2021-10-01 15:30.000
    1         ABCD       2021-10-01 15:45.000
    2         ABCDE      2021-10-01 19:00.000
    2         ABCDE      2021-10-01 19:56.000
    2         ABCDE      2021-10-01 20:00.000

Output expected would be:
 Position    Count    Lot
    1          3     ABCD
    2          3     ABCDE

Select DISTINCT COUNT(POSITION) AS COUNT, LOT
FROM DATA1
GROUP BY POSITION;

I get a 2 count instead of 3.我得到 2 计数而不是 3。

DISTINCT applies to the whole resultset and is usually applied incorrectly. DISTINCT适用于整个结果集,通常应用不正确。 Based on the 6 rows of sample data, my first guess is:根据 6 行样本数据,我的第一个猜测是:

SELECT Position, Lot, [Count] = COUNT(*) 
  FROM dbo.Data1
  GROUP BY Position, Lot;

Check this.检查这个。

SELECT Position, COUNT(Position) AS Count, Lot
FROM  DATA1
GROUP BY Position, Lot

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM