-2

I want to create a query that satisfies these criteria:

  1. It counts the number of distinct values for each column.
  2. It selects the top three columns that have the greatest number of distinct values.
  3. It counts the number of distinct values contained in the power set of those top three columns.

This is what I've got so far:

SELECT TOP(3) COUNT(DISTINCT column_name) AS some_alias FROM tablename 
    GROUP BY ~ ORDER BY count(*) asc

What is wrong with my query?

chb
  • 1,727
  • 7
  • 25
  • 47
bmer
  • 47
  • 9
  • 2
    Homework questions usually need to show some effort to get help, but your question isn't even clear because there is no data whatsoever. – Tim Biegeleisen Jan 31 '17 at 05:54
  • Tag the dbms you're using, some non-ANSI SQL there... – jarlh Jan 31 '17 at 07:42
  • Create the table. Add some data, both distinct and duplicates. Try your query! (By trying, you'll learn much faster!) – jarlh Jan 31 '17 at 07:43

1 Answers1

0

use distinct value inside subquery then use count in select query like below.

SELECT columnName,
   COUNT(col1) AS Col,
   COUNT(col2) AS col2

FROM
(
    SELECT DISTINCT
           columnName,
           Col1,
           col2
    FROM table
)

GROUP BY columnName;
anatol
  • 1,680
  • 2
  • 24
  • 47
Singh Kailash
  • 621
  • 5
  • 16
  • SELECT TOP(3) COUNT(DISTINCT column_name) AS some_alias FROM tablename GROUP BY ~ ORDER BY count(*) asc -> Is this sql alright? – bmer Jan 31 '17 at 07:34