Sql 如何在某些列上计算distinct

Sql 如何在某些列上计算distinct,sql,Sql,希望在SQL结果中添加一个计数列,以便在同一天读取相同的电子邮件时对与1相同的reportID计数进行计数 DB#报告: 我的SQL如下所示,但无法计算进行计数的预期结果。 它生成数据库中的所有行,并且everyrow count=1 Select ReportId,Name,Country, Doc, Date, count(distinct concat(ReportId,Date,email)) from #Report Group by Reportid,Name,Country, Do

希望在SQL结果中添加一个计数列,以便在同一天读取相同的电子邮件时对与1相同的reportID计数进行计数

DB#报告:

我的SQL如下所示,但无法计算进行计数的预期结果。 它生成数据库中的所有行,并且everyrow count=1

Select ReportId,Name,Country, Doc, Date, count(distinct concat(ReportId,Date,email))
from #Report
Group by Reportid,Name,Country, Doc, Date, email

你可以试试这个。只需从分组依据中删除
Date
列即可

Select ReportId,Name,Country, Doc, MIN(Date) Date, count(distinct concat(ReportId,Date,email))
from #Report
Group by Reportid,Name,Country, Doc, email

请尝试此选项,仅在ReportId、email和add readdate上分组不为空条件。它将为您提供不同ReportId、电子邮件、readdate的计数,并将获取所有其他字段的最小值

考虑到ReportId和email不是空字段

Select ReportId, email, MIN(readdate), MIN(name), MIN(country), MIN(Doc), count(*) as Count
from Report
where readdate is not null 
Group by ReportId, email

你用的是什么数据库?如果是SQL Server,是什么版本?
Select ReportId, email, MIN(readdate), MIN(name), MIN(country), MIN(Doc), count(*) as Count
from Report
where readdate is not null 
Group by ReportId, email