Q. Consider the CUSTOMERS table having the following records:


Table: CUSTOMERS


 
ID NAME AGE ADDRESS SALARY
1 Ramesh 32 Ahmedabad 2000.00
2 Khilan 25 Delhi 1500.00
3 Kaushik 23 Kota 2000.00
4 Chaitali 25 Mumbai 6500.00
5 Hardik 27 Bhopal 8500.00
6 Komal 22 Bengaluru 4500.00
7 Muffy 24 Indore 10000.00

(a) Write an SQL query to display all records in ascending order of name.

(b) Write an SQL query to display all records in descending order of name.

(c) Write an SQL query to display all records in ascending order of name and  descending order of age.

(d) Write an SQL query to display maximum salary.

(e) Write an SQL query to display minimum salary.

(f) Write an SQL query to display total number of records.

(g) Write an SQL query to display average salary.

(h) Write an SQL query to display total salary of all the persons.

(i) Write an SQL query to display names of those persons whose salary is greater than the average salary.

(j) Write an SQL query to display details of those persons whose age is less than the average age.


Answer :-

(a) Select * from Customer order by name ;
(b) Select * from Customer order by name Desc ;
(c) Select * from Customer order by name , age Desc ;
(d) Select max( Salary ) from Customer ;
(e) Select min( Salary ) from Customer ;
(f) Select count( * ) from Customer ;
(g) Select Avg( Salary ) from Customer ;
(h) Select Sum( Salary ) from Customer ;
(i) Select name from Customer where (Select avg ( Salary ) from Customer ) > Salary ;
(j) Select * from Customer where (Select avg ( age ) from Customer ) >  age ;

5 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

  1. 1Display all columns of the employee table whose age is between 35 and 50 living in KOta, Mumbai, or Delhi.

    ReplyDelete
    Replies
    1. Select * from customer where age between 35 and 50 and address in ("Kota","Mumbai","Delhi") ;

      Delete
  2. In C option answer output is showing as..for name but not for age desc...what to do?

    ReplyDelete
  3. We need to give separate query for c option for asc name and desc age right?? It's not working for both in single query..

    ReplyDelete
    Replies
    1. I think you are doing some small mistake so, please copy query as it is and paste it.

      Delete

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post