If you can't read please download the document
Upload
ritwik-das
View
751
Download
2
Embed Size (px)
Citation preview
MySql COUNT() function
Ref: w3resource MySQL Tutorial
MySQL Count function
MySQL COUNT() function returns a count of numberof non-NULL values of a given expression.
If it does not find any matching row, it returns 0.
Here is the Syntax:
COUNT(expr);
We will see different types of usage of MySQL Count function in a moment.
MySQL Count function
Table for demonstration:
MySQL Count function
To return the number of rows in author table:
SELECT COUNT(*) FROM author;
MySQL COUNT() with logical operator:
SELECT country,pub_city,COUNT(*) FROM publisher WHERE country='USA' OR country='UK' GROUP BY country,pub_city;
MySQL Count function
MySQL COUNT() using multiple tables:
Table book_mast
MySQL Count function
MySQL COUNT() using multiple tables:
Table book_mast
MySQL Count function
SELECT publisher.pub_name,COUNT(*)FROM publisher,book_mastWHERE publisher.pub_id=book_mast.pub_idGROUP BY publisher.pub_id;
MySQL COUNT() function with GROUP BY
SELECT country,COUNT(*)FROM author GROUP BY country;
MySQL COUNT() function with group by on multiple columns
SELECT country,pub_city,COUNT(*)FROM publisher GROUP BY country,pub_city;
MySQL Count function
SELECT cate_id,COUNT(DISTINCT(pub_lang)), ROUND(AVG(no_page),2)FROM book_mastGROUP BY cate_id;
MySQL COUNT() function with distinct
CLIQUE PARA EDITAR O FORMATO DO TEXTO DO TTULO
Clique para editar o formato do texto da estrutura de tpicos2. Nvel da estrutura de tpicos3. Nvel da estrutura de tpicos4. Nvel da estrutura de tpicos5. Nvel da estrutura de tpicos6. Nvel da estrutura de tpicos7. Nvel da estrutura de tpicos