0% found this document useful (0 votes)
31 views

MySQL - Functions - Worksheet

1. Formats the date of joining in the specified format if it is not a Sunday.

Uploaded by

Naseema Syed
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views

MySQL - Functions - Worksheet

1. Formats the date of joining in the specified format if it is not a Sunday.

Uploaded by

Naseema Syed
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Write the output produced by the following SQL commands:

a) SELECT POW(2,3);

b) SELECT ROUND(123.2345, 2), ROUND(342.9234,-1);

c) SELECT LENGTH("Informatics Practices");

d) SELECT YEAR(“1979/11/26”), MONTH(“1979/11/26”), DAY(“1979/11/26”),


MONTHNAME(“1979/11/26”);

e) SELECT LEFT("INDIA",3), RIGHT("Computer Science",4);

f) SELECT MID("Informatics",3,4), SUBSTR("Practices",3);

g) select dayofmonth(curdate());

h) select truncate(2345.456789.2)
1. if the date of joining is not a Sunday, then display it in the following

format "Wednesday, 26, November 1979."

2. Display the names of the employees who joined in the month of December.
3. Display the age of the employee at time of joining. [approximate age]
4. Display the present age of the employee.
5. select max(year(DOB)) from emp;
6. Display the total amount spent on salary.
7. Display the employee names who joined in oct month
8. Display the last 3 characters of employee name

1. Display the length of the email and part of the email from the email ID before the character
‘@’. Note - Do not print ‘@’.
2. Display four digit area code is reflected in the phone number starting from position number
3. For example, 1851 is the area code of mobile number 9818511338. Now, write the SQL
query to display the area code of the customer.
3. Display emails after removing the domain name extension “.com” from emails of the
customers

Order by and group by

Order by based on multiple columns

Syntac : order by col_name [Asc|Desc] , col_name [Asc|Desc],....;

Order by based on expression :


1. Write a query to display the name, dept and experience, firstly sorted by dept in Descending
order and then by experience in ascending order.

2. display name and experience*0.2, sorted by experience*0.2 in descending order

Demonstrate the difference between sysdate() and Now()

Grouping can be done by a column_name or aggregate function

In a select list use a grouped field or aggregate functions

1. Display the dept_name and highest no of experience of a doctor is each department

Select dept, max(experience) from emp group by dept

2. Display the number of male and female doctors

3. Display the number of doctors in each department

4. Display the number of female doctors in each department.

Select count(name) from emp group by department having sex=’F’;

Select dept, count(name) from emp where sex=’F’ group by department

5. Display the department names which contain more than one doctor .

Select ______ from emp group by department having count(department)>1

You might also like