0% found this document useful (0 votes)
24 views1 page

SQL Queries for Employee Data Analysis

The document contains a series of SQL queries related to employee and customer data retrieval from various tables. It includes queries to filter employees based on salary, commission, job title, and name patterns, as well as customer ratings and student grades. Each query is presented with its corresponding SQL syntax for clarity.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views1 page

SQL Queries for Employee Data Analysis

The document contains a series of SQL queries related to employee and customer data retrieval from various tables. It includes queries to filter employees based on salary, commission, job title, and name patterns, as well as customer ratings and student grades. Each query is presented with its corresponding SQL syntax for clarity.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Q1.

Write a query to display EName and Sal of employees whose salary is greater than or
equal to 2200 from table Empl.

Ans: SELECT EName, Sal FROM Empl WHERE sal >= 2200;

Q2. Write a query to display details of employees who are not getting commission from table
Empl.

Ans: SELECT * FROM EMPL WHREE COMM IS NULL;

Q3. Write a query to display employee name and salary of those employee who don’t have
there salary in the range of 2500 to 4000.

Ans: SELECT ENAME, SAL FROM EMPL WHERE SAL NOT BETWEEN 2500 AND 4000;

Q4. Write a query to display the name, job title and salary of employee who do not have
manager.

Ans: SELECT ENAME, JOB, SAL FROM EMPL WHERE MGR IS NULL;

Q5. Write a query to display the name of employee whose name contains ‘A’ as third alphabet.

Ans: SELECT ENAME FROM EMPL WHERE ENAME LIKE ‘_ _ A%’;

Q6. Write a query to display the name of employee whose name contains ‘T’ as the last
alphabet.

Ans: SELECT ENAME FROM EMPL WHERE ENAME LIKE ‘%T’;

Q7. Write a query to display the name of employee whose name contains ‘M’ as first alphabet
‘L’ as third alphabet.

Ans: SELECT ENAME FROM EMPL WHERE ENAME LIKE ‘M_L%’;

Q8. Write a query on the customers table whose output will exclude all customers with a rating
<= 100, unless they are located in Shimla.

Ans: SELECT * FROM CUSTOMERS WHERE RATING <=100 OR CITY = ‘SHIMLA’;

Q9. Write a query that selects all orders (Order table) except those with zeros or NULLs in the
amt field.

Ans: SELECT * FROM ORDER WHERE AMT <> 0 OR AMT IS NOT NULL;

(i) Display the names of the students who are getting a grade ‘C’ in either GAME or SUPW.

Ans: SELECT NAME FROM STUDENT WHERE GRADE1 =’C’ OR GRADE2 = ‘C’;

(ii) Display the different games offered in the school.

Ans: SELECT DISTINCT GAME FROM STUDENT;

(iil) Display the SUPW taken up by the students, whose name starts with ‘A’.

Ans: SELECT SUPW, NAME FROM STUDENT WHERE NAME LIKE ‘A%’;

Common questions

Powered by AI

The SQL query would be structured as: SELECT NAME FROM STUDENT WHERE (GRADE1 = 'C' OR GRADE2 = 'C') AND NAME LIKE 'A%'; This filters students based on their grades and initial letter of their names at the same time .

To list only the distinct games offered at the school, use: SELECT DISTINCT GAME FROM STUDENT; This query will return a list of games without duplicates, ensuring each game is mentioned only once .

The query for listing all orders without nulls or zeros is: SELECT * FROM ORDER WHERE AMT <> 0 AND AMT IS NOT NULL; It ensures all retrieved orders have a defined, non-zero amount .

The query would be: SELECT * FROM CUSTOMERS WHERE RATING > 100 OR CITY = 'SHIMLA'; This logic includes all Shimla residents despite their ratings and excludes others rated below 100 .

The query would be: SELECT ENAME FROM EMPL WHERE ENAME LIKE 'M_L%'; This pattern-based query searches for names with these specific character positions defined .

To retrieve customers with a rating greater than 100 and exclude those in Shimla, you can write: SELECT * FROM CUSTOMERS WHERE RATING > 100 AND CITY <> 'SHIMLA'; This query specifically selects customers who exceed the rating threshold unless they are located in Shimla .

To display employee names and salaries for those whose salaries are neither between 2500 and 4000 nor above 4000, you can combine conditions with the NOT BETWEEN operator as follows: SELECT ENAME, SAL FROM EMPL WHERE SAL < 2500 OR SAL > 4000. This ensures we only select employees whose salaries fall outside the specified range .

To retrieve students whose SUPW names start with 'A', use: SELECT SUPW, NAME FROM STUDENT WHERE NAME LIKE 'A%'; This query effectively utilizes SQL wildcard to filter results based on the starting character of the students' names .

The SQL query to select employees who do not receive commissions and have salaries over 2200 is: SELECT ENAME, SAL FROM EMPL WHERE COMM IS NULL AND SAL > 2200; This ensures the retrieved employees meet both criteria .

To find employees with no manager and a name ending in 'T', you can use a combination of conditions: SELECT ENAME FROM EMPL WHERE MGR IS NULL AND ENAME LIKE '%T'; This ensures the query checks for both conditions simultaneously .

You might also like