Count distinct value pairs in multiple columns in SQL

前端 未结 5 2050
终归单人心
终归单人心 2021-01-31 17:14

What query will count the number of rows, but distinct by three parameters?

Example:

Id      Name        Address 
==============================
1     My         


        
5条回答
  •  暖寄归人
    2021-01-31 17:33

    Having to return the count of a unique Bill of Materials (BOM) where each BOM have multiple positions, I dd something like this:

    select t_item, t_pono, count(distinct ltrim(rtrim(t_item)) + cast(t_pono as varchar(3))) as [BOM Pono Count]
    from BOMMaster
    where t_pono = 1
    group by t_item, t_pono
    

    Given t_pono is a smallint datatype and t_item is a varchar(16) datatype

提交回复
热议问题