Hi,
I have a SQL query that looks like this:
SELECT department, count(distinct person_id) AS NumberOfPersons
FROM person
GROUP BY department
FROM person
GROUP BY department
This query wil show me how many persons that are employed on departments. A person with same person_id can exist on several records in the person table therefore I have used distinct before count.
Because of performance issue I did not want to use DISTINCT!
How can I rewrite this SQL whith no DISTINCT in the SELECT statement?
Manas TripathiRank #7,584 · 238 reputationPosted Mar 22, 2018, 8:31 PM EDT
Joseph ThomasRank #1,535 · 1K reputationPosted Mar 21, 2018, 10:22 PM EDT
Manas TripathiRank #7,584 · 238 reputationPosted Mar 20, 2018, 3:30 PM EDT
Hakan AxheimRank #8,316 · 224 reputationPosted Mar 20, 2018, 8:17 PM EDT
Manish KumarRank #1,622 · 956 reputationPosted Mar 20, 2018, 11:07 PM EDT
Hakan AxheimRank #8,316 · 224 reputationPosted Mar 21, 2018, 12:18 AM EDT
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts