我正在尝试计算具有相关查询的所有行。但是“计数”功能无法正常工作,并提供了无效的号码。
我执行不带Count函数的查询,并且行数正确。
第一个查询:
SELECT
*
from [db_ip].[DBNAME].dbo.Cards Cards
inner JOIN [db_ip].[DBNAME].dbo.Products Products ON Cards.ProductID = Products.ProductID
inner JOIN [db_ip].[DBNAME].dbo.Subjects Subjects ON Products.SubjectID = Subjects.SubjectID
inner JOIN [db_ip].[DBNAME].dbo.CardStatusTypes CardStatusTypes ON Cards.CardStatusTypeID = CardStatusTypes.ID
inner JOIN [db_ip].[DBNAME].dbo.Applications Applications ON Products.ApplicationID = Applications.ApplicationID
inner JOIN [db_ip].[DBNAME].dbo.Branches Branches ON Applications.DeliverBranchID = Branches.ID
inner JOIN [db_ip].[DBNAME].dbo.ApplicationPersons ApplicationPersons ON Applications.ApplicationID = ApplicationPersons.ApplicationID
inner JOIN [db_ip].[DBNAME].dbo.ApplicationOrganizations ApplicationOrganizations on Applications.ApplicationID=ApplicationOrganizations.ApplicationID
inner join [db_ip].[DBNAME].dbo.Certificates Certificates on Products.ProductID = Certificates.ProductID
inner join [db_ip].[DBNAME].dbo.CertificateStatusHistory CertificateStatusHistory on Certificates.CertificateID = CertificateStatusHistory.CertificateID
inner join [db_ip].[DBNAME].dbo.CertificateStatusTypes CertificateStatusTypes on CertificateStatusHistory.StatusTypeID = CertificateStatusTypes.ID
WHERE Personalized <> '' and Certificates.CertificateTypeID = 2 and
(CardStatusTypes.ID = 10 or CardStatusTypes.ID = 101 or CardStatusTypes.ID = 3) and CertificateStatusTypes.Id = 1
and Personalized >= '2011-01-01' and Personalized < '2019-01-01'
执行完此查询后,在底部右侧显示了网格中显示的行数。例如是45652。
但是当我尝试使用“计数”功能进行相同的查询时,它会显示111510
而且即使我改变时间也没有改变。
查询:
SELECT
count(*)
from [db_ip].[DBNAME].dbo.Cards Cards
inner JOIN [db_ip].[DBNAME].dbo.Products Products ON Cards.ProductID = Products.ProductID
inner JOIN [db_ip].[DBNAME].dbo.Subjects Subjects ON Products.SubjectID = Subjects.SubjectID
inner JOIN [db_ip].[DBNAME].dbo.CardStatusTypes CardStatusTypes ON Cards.CardStatusTypeID = CardStatusTypes.ID
inner JOIN [db_ip].[DBNAME].dbo.Applications Applications ON Products.ApplicationID = Applications.ApplicationID
inner JOIN [db_ip].[DBNAME].dbo.Branches Branches ON Applications.DeliverBranchID = Branches.ID
inner JOIN [db_ip].[DBNAME].dbo.ApplicationPersons ApplicationPersons ON Applications.ApplicationID = ApplicationPersons.ApplicationID
inner JOIN [db_ip].[DBNAME].dbo.ApplicationOrganizations ApplicationOrganizations on Applications.ApplicationID=ApplicationOrganizations.ApplicationID
inner join [db_ip].[DBNAME].dbo.Certificates Certificates on Products.ProductID = Certificates.ProductID
inner join [db_ip].[DBNAME].dbo.CertificateStatusHistory CertificateStatusHistory on Certificates.CertificateID = CertificateStatusHistory.CertificateID
inner join [db_ip].[DBNAME].dbo.CertificateStatusTypes CertificateStatusTypes on CertificateStatusHistory.StatusTypeID = CertificateStatusTypes.ID
WHERE Personalized <> '' and Certificates.CertificateTypeID = 2 and
(CardStatusTypes.ID = 10 or CardStatusTypes.ID = 101 or CardStatusTypes.ID = 3) and CertificateStatusTypes.Id = 1
and Personalized >= '2011-01-01' and Personalized < '2019-01-01'