Advertisements
Advertisements
प्रश्न
Construct the following SQL statement in the student table-
SELECT statement using GROUP BY clause.
उत्तर
GROUP BY clause
The GROUP BY clause is used with the SELECT statement to group the students on rows or columns having identical values or divide the table into groups. For example to know the number of male students or female students of a class, the GROUP BY clause may be used. It is mostly used in conjunction with aggregate functions to produce summary reports from the database.
The syntax for the GROUP BY clause is
SELECT <column-names> FROM <table-name> GROUP BY <column-name>HAVING condition];
To apply the above command on the student table :
SELECT Gender FROM Student GROUP BY Gender;
The following command will give the below-given result:
Gender |
M |
F |
SELECT Gender, count(*) FROM Student GROUP BY Gender;
Gender | count(*) |
M | 5 |
F | 3 |
APPEARS IN
संबंधित प्रश्न
The command to delete a table is ______
The clause used to sort data in a database.
Write a query that selects all students whose age is less than 18 in order wise.
Differentiate Unique and Primary Key constraint.
Write the use of the Savepoint command with an example.
Consider the following employee table. Write SQL commands for the question.
EMP CODE | NAME | DESIG | PAY | ALLO WANCE |
S1001 | Hariharan | Supervisor | 29000 | 12000 |
P1002 | Shaji | Operator | 10000 | 5500 |
P1003 | Prasad | Operator | 12000 | 6500 |
C1004 | Manjima | Clerk | 8000 | 4500 |
M1005 | Ratheesh | Mechanic | 20000 | 7000 |
To display all employees whose allowance is between 5000 and 7000.
Consider the following employee table. Write SQL commands for the question.
EMP CODE | NAME | DESIG | PAY | ALLO WANCE |
S1001 | Hariharan | Supervisor | 29000 | 12000 |
P1002 | Shaji | Operator | 10000 | 5500 |
P1003 | Prasad | Operator | 12000 | 6500 |
C1004 | Manjima | Clerk | 8000 | 4500 |
M1005 | Ratheesh | Mechanic | 20000 | 7000 |
To remove the employees who are mechanics.
Consider the following employee table. Write SQL commands for the question.
EMP CODE | NAME | DESIG | PAY | ALLO WANCE |
S1001 | Hariharan | Supervisor | 29000 | 12000 |
P1002 | Shaji | Operator | 10000 | 5500 |
P1003 | Prasad | Operator | 12000 | 6500 |
C1004 | Manjima | Clerk | 8000 | 4500 |
M1005 | Ratheesh | Mechanic | 20000 | 7000 |
To add a new row.
Construct the following SQL statement in the student table-
SELECT statement using ORDER BY clause.
Write a SQL statement to create a table for employees having any five fields and create a table constraint for the employee table.