1

I am new to SQL and learning some basic things with Treasure Data. I have many records of reservation in a table with 11 distinct resource values that users can reserve.

This gives me the resources in a table:

SELECT 
  DISTINCT resource
FROM
  reservation
;

But what if I just want the output to be the number of records that get returned by the query (i.e., "11").

This doesn't work:

SELECT 
  COUNT(*) DISTINCT resource
FROM
  reservation
;

What is the right syntax for this? I have not been able to figure this out.

Mureinik
  • 297,002
  • 52
  • 306
  • 350
james
  • 519
  • 3
  • 10
  • 19
  • (1) Learn `group by`. (2) Tag your question with the database you are actually using. I'm removing the extraneous database tags. – Gordon Linoff Nov 04 '15 at 20:05

1 Answers1

2

The distinct keyword goes inside the aggregate function:

SELECT 
  COUNT(DISTINCT resource)
FROM
  reservation
;
Mureinik
  • 297,002
  • 52
  • 306
  • 350