问题编写计数SQL查询并显示结果

时间:2018-05-17 15:01:52

标签: sql

我在将此查询转换为Count查询时遇到问题,是否有人能够提供帮助。我基本上想要计算此日期返回的记录数,理想情况下会在一个表中显示数据库名称,然后显示总计数。 例如。在这个例子中将是Test then 6

SELECT
    test.dbo.OrderedDocuments.UserDocumentID, 
    OrderedDocuments.OrderGroupID, OrderGroups.TimePlaced 
FROM
    OrderedDocuments 
INNER JOIN 
    OrderGroups ON OrderedDocuments.OrderGroupID = OrderGroups.OrderGroupID
WHERE 
    OrderGroups.TimePlaced > '2018-05-17'

2 个答案:

答案 0 :(得分:0)

如果要显示计数,请使用import { map, delay, catchError } from 'rxjs/operators'; source.pipe( map(x => x + x), delay(4000), catchError(err => of('error found')), ).subscribe(printResult); 函数:

例如:

count()

如果您希望获得部门计数,请使用SELECT count(*) Total_count FROM OrderedDocuments INNER JOIN OrderGroups ON OrderedDocuments.OrderGroupID = OrderGroups.OrderGroupID WHERE OrderGroups.TimePlaced >'2018-05-17'; 子句获取部门计数

答案 1 :(得分:0)

根据我的理解(假设UserDocumentID是您想要查看计数的字段),您可能希望这样做:

SELECT od.UserDocumentID, COUNT(*) as Total
FROM  OrderedDocuments od
INNER JOIN OrderGroups og
   ON od.OrderGroupID = og.OrderGroupID
WHERE og.TimePlaced >'2018-05-17'
GROUP BY od.UserDocumentID