
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
Get number of users of different type in MySQL?
Let us first create a table −
mysql> create table DemoTable -> ( -> UserName varchar(20), -> UserType ENUM('New User','Registered User') -> ); Query OK, 0 rows affected (0.60 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('Chris','New User'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('David','New User'); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable values('Mike','Registered User'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable values('Sam','New User'); Query OK, 1 row affected (0.10 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable;
This will produce the following output −
+----------+-----------------+ | UserName | UserType | +----------+-----------------+ | Chris | New User | | David | New User | | Mike | Registered User | | Sam | New User | +----------+-----------------+ 4 rows in set (0.00 sec)
Here is the query to get number of users of different type −
mysql> select count(*),UserType from DemoTable group by UserType;
This will produce the following output−
+----------+-----------------+ | count(*) | UserType | +----------+-----------------+ | 3 | New User | | 1 | Registered User | +----------+-----------------+ 2 rows in set (0.00 sec)
- Related Articles
- Different Types of Database Users
- Get the type of a variable in MySQL?
- MySQL Select to get users who have logged in today?
- Explain the different categories of End Users in DBMS?
- Explain the different types of users who play different roles in DBMS?
- Get number of fields in MySQL table?
- List logged-in MySQL users?
- what are the different attributes of MySQL ENUM data type?
- Get the number of columns in a MySQL table?
- Get at least x number of rows in MySQL?
- How do PayPal users get scammed?
- Get the week number in MySQL for day of week?
- Get total number of rows while using LIMIT in MySQL?
- Get count of zeros for columns values declared with INT type in MySQL
- How to merge queries in a single MySQL query to get the count of different values in different columns?

Advertisements