Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Mysql count

788 views

Published on

MySQL COUNT() function returns a count of number of non-NULL values of a given expression.

If it does not find any matching row, it returns 0.

  • Be the first to comment

  • Be the first to like this

Mysql count

  1. 1. MySql COUNT() function Ref: w3resource MySQL Tutorial
  2. 2. 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 MySQLCount function in a moment.
  3. 3. MySQL Count functionTable for demonstration:
  4. 4. MySQL Count functionTo 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;
  5. 5. MySQL Count functionMySQL COUNT() using multiple tables: Table book_mast
  6. 6. MySQL Count functionMySQL COUNT() using multiple tables:Table book_mast
  7. 7. MySQL Count function SELECT publisher.pub_name,COUNT(*) FROM publisher,book_mast WHERE publisher.pub_id=book_mast.pub_id GROUP 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;
  8. 8. MySQL Count functionMySQL COUNT() function with distinct SELECT cate_id,COUNT(DISTINCT(pub_lang)), ROUND(AVG(no_page),2) FROM book_mast GROUP BY cate_id;

×