How to do COUNT () or COUNT (*)

I have a list of tags in the database.

Example:

villan
hero
spiderman
superman
superman

I wanted to get a sorted list of tag names in ascending order and the number of times a unique unique tag appeared in the database. I wrote this code:

Example:

 SELECT hashtag.tag_name
      , COUNT( * ) AS number
   FROM hashtag 
  GROUP BY hashtag.tag_name
  ORDER BY hashtag.tag_name ASC

This gives the correct result:

 hero      , 1
 spiderman , 1
 superman  , 2
 villan    , 1

How can I get the full COUNT of this whole list. The answer should be 4 in this case, because there are naturally 4 lines. It seems I cannot get the correct COUNT () without operator error.

Thank you very much for your help!:)

+5
source share
4 answers
SELECT COUNT(DISTINCT `tag_name`) FROM `hashtag`
+6
source

COUNT DISTINCT(hashtag.tag_name) - SELECT, (, , UNION), SELECT ( UNION) , .

+1

my-sql, .

SELECT hashtag.tag_name, count(*) FROM hashtag GROUP BY cube(hashtag.tag_name)
0

, ( ), , :

SELECT COUNT(*) AS uniquetags
FROM (SELECT hashtag.tag_name, COUNT( * ) AS number
      FROM hashtag GROUP BY hashtag.tag_name
      ORDER BY hashtag.tag_name ASC)

, ORDER BY COUNT, COUNT.

, , - COUNT DISTINCT, :

SELECT COUNT(DISTINCT hashtag.tag_name)
FROM hashtag

, , , . -, , ( EXPLAIN s).

0
source

All Articles