

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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 Questions & Answers
- Explain the different categories of End Users in DBMS?
- Explain the different types of users who play different roles in DBMS?
- Get the type of a variable in MySQL?
- what are the different attributes of MySQL ENUM data type?
- Get number of fields in MySQL table?
- MySQL Select to get users who have logged in today?
- List logged-in MySQL users?
- 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 underlying type of the current enumeration type C#
- Get total number of rows while using LIMIT in MySQL?
- Get the week number in MySQL for day of week?
- Get count of zeros for columns values declared with INT type in MySQL
- What type of datatype should I use (MySQL) with a mix of string and number?
Advertisements