SQL Server count number of distinct values in each column of a table

前端 未结 5 969
别跟我提以往
别跟我提以往 2020-12-10 10:06

I have a table with ~150 columns. I\'d like to find the count(distinct(colName)) for each column but am wondering if there\'s a way to do so without actually t

5条回答
  •  醉话见心
    2020-12-10 10:18

    This should do:

    select count(*) from (select distinct * from myTable) as t
    

    Here is SQL Fiddle test.

    create table Data
    (
        Id int,
        Data varchar(50)
    )
    
    insert into Data 
    select 1, 'ABC'
    union all
    select 1, 'ABC'
    
    select count(*) 
    from (select distinct * from Data) as t
    

提交回复
热议问题