Home > Database > Mysql Tutorial > How to Count Distinct Program Names by Type and Push Number in SQL Server 2005?

How to Count Distinct Program Names by Type and Push Number in SQL Server 2005?

DDD
Release: 2025-01-14 19:02:13
Original
318 people have browsed it

How to Count Distinct Program Names by Type and Push Number in SQL Server 2005?

SQL Server 2005: Counting Unique Program Names by Type and Push Number

This guide demonstrates how to efficiently count distinct program names, categorized by program type and a given push number, within SQL Server 2005. A common mistake is overlooking the need for distinct counting.

The COUNT(DISTINCT <expression>) function is the key to accurate results. This function counts only unique, non-null values of the specified expression within each group.

Here's the corrected SQL query:

<code class="language-sql">SELECT program_type AS [Type],
       COUNT(DISTINCT program_name) AS [Count]
FROM   cm_production
WHERE  push_number = @push_number
GROUP  BY program_type</code>
Copy after login

This query effectively counts distinct program names for each program type, filtered by the provided @push_number parameter. The output clearly shows the desired counts for each program type.

The above is the detailed content of How to Count Distinct Program Names by Type and Push Number in SQL Server 2005?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template