Link to home
Start Free TrialLog in
Avatar of Harreni
HarreniFlag for Saudi Arabia

asked on

Writing a SQL Server Query to find Totals

Hi Experts,

I want to write a SQL Server query for the attached table  to find the below:
1- Total number of service related to Consumer # AC056 without duplication.
2- Total number of datasets related to Consumer # AC056 without duplication.
3- Total number of providers related to Consumer # AC056 without duplication.
4- Total number of datasets for each service ID without duplication.

User generated image


Thanks a lot.
Harreni
Avatar of Vitor Montalvão
Vitor Montalvão
Flag of Switzerland image

Please define when a record is duplicated. Which columns should be considered? Which columns are the primary key?
Use the above table to mark the duplicated records.
ASKER CERTIFIED SOLUTION
Avatar of Docteur_Z
Docteur_Z
Flag of France image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Sean Stuber
Sean Stuber

select count(distinct serviceid) from yourtable where consumerid = 'AC056';

select count(distinct datasetid) from yourtable where consumerid = 'AC056';

select count(distinct providerid) from yourtable where consumerid = 'AC056';

select count(distinct datasetid) from yourtable where consumerid = 'AC056';
Avatar of Harreni

ASKER

Thanks a lot Vitor, Docteur_Z and sdstuber.