Question

From the l_employees table, list all the different combinations of dept_code and credit_limit. Count the number...

From the l_employees table, list all the different combinations of dept_code and credit_limit. Count the number of employees who are in each of these categories. Sort the rows by dept_code and then by credit_limit. Exclude the ‘SHP’ department in your results. Show only the dept_code, with a credit limit of over 12.50. Show your sql below.

Show me code step by step and or take screenshots of code and run test.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Hi,
Your are not sharing the structure of table l_employees which your using. But based on your question I'm creating one table which can reproducible all your question,
Take loop at table which I created:

create table if not exists l_employees(
   employ_name varchar(30) not null,
   dept_code varchar(10),
   credit_limit decimal(8,2),
   department varchar(10)
);

here i'm assuming dept_code is varchar of length 10, credit_limit of 8 length and 2 decimal points max(999999.99) and etc.

Insert some data into table using insert query:

insert into l_employees values("Shiva","ADMIN", 500000.00, "ADM");
insert into l_employees values("Venkat","HR", 600000.00, "ADM");
insert into l_employees values("Venky","DEV", 700000.00, "SHP");
insert into l_employees values("Swathi","QA", 800000.00, "ADM");
insert into l_employees values("Pooji",null, 400000.00, "ADM");
insert into l_employees values("Adi","BUSS", 300000.00, "SHP");
insert into l_employees values("Amara","ADMIN", null, "ADM");
insert into l_employees values("Ammu","DEV", 550000.00, "SHP");
insert into l_employees values("Kiran","DEV", 880000.00, "ADM");

After inserting take a loop at what table contains: (you can use select * from l_employees;)

Now let's start your questions:

1. List all the different combinations of dept_code and credit_limit :
SQL command you required for this is:

select d.dept_code,c.credit_limit
from (select distinct credit_limit from l_employees) c cross join
(select distinct dept_code from l_employees) d;

here d and c are variable which are pointing to dept_code and credit_limit respectively.
distinct credit_limit from l_employees return all unique values of credit_limit column values similarly select distinct dept_code from l_employees.

cross join : is SQL gives the all possible combination of two sets.

Output after executing above commad is :

2. Count the number of employees who are in each of these categories:

Here I took two categories are  dept_code and credit_limit, employees belongs each of these categories means all employees which are having both these categories as not null.

To achieve that required command id :

SELECT COUNT(*) FROM l_employees where dept_code is not null and credit_limit is not null;

Here count(*) returns one column as count, and values from l_employees table where dept_code is not null and credit_limit is also not null.

Output after this command:

because table have total 9 rows and 2 rows having null values. So answer is 7

Note: You can count any combination using below syntax
select count(*) from table_name where condition1,condition2.etc; example select count(*) where credit_limit > 500000.00 and department = "ADM"

3.Sort the rows by dept_code and then by credit_limit:
Command for this is:

select * from l_employees order by dept_code,credit_limit;

here order by returns sorted list with respective to column dept_code and column credit_limit.

Syntax is : select * from table_name order by column1,column2..etc;

Output:

4.Exclude the ‘SHP’ department in your results:

For this you only require where clause to avoid SHP department;

Examples :
1. avoid SHP department in problem1:

select d.dept_code,c.credit_limit
from (select distinct credit_limit from l_employees where department != "SHP") c cross join
(select distinct dept_code from l_employees where department != "SHP") d;

result is:

2. avoid SHP department in problem2:

SELECT COUNT(*) FROM l_employees where dept_code is not null and credit_limit is not null and department != "SHP";
Output:

3.  avoid SHP department in problem3:

select * from l_employees where department != "SHP" order by dept_code,credit_limit;
Output:

5.   Show only the dept_code, with a credit limit of over 12.50 :
For the best suit with current table I'm making credit_card limit to 500000.00

command is:

select distinct dept_code from l_employees where credit_limit > 500000.00;
Output:

All commands at once:

Hope you got what you want . Cheers..?????!

Add a comment
Know the answer?
Add Answer to:
From the l_employees table, list all the different combinations of dept_code and credit_limit. Count the number...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Which SQL statement retrieves the EmployeeName and City columns from the Employees table? O LIST EmployeeName,...

    Which SQL statement retrieves the EmployeeName and City columns from the Employees table? O LIST EmployeeName, City ON Employees; O FIND EmployeeName, City ON Employees; SELECT EmployeeName, City FROM Employees; O RETRIEVE EmployeeName, City FROM Employees; Which SQL statement finds the different cities in which national parks reside with no duplicate rows listed? SELECT DISTINCT city FROM natlpark ORDER BY city; O ORDER BY natlpark DISTINCT city; O ORDER BY city FROM natlpark; O SELECT city FROM natlpark ORDER BY...

  • Using SQL*Plus on OMEGA, access the tables you created in Project 2 and complete the following...

    Using SQL*Plus on OMEGA, access the tables you created in Project 2 and complete the following SQL transactions. Log your statements and results by spooling your file (with echo on). Directions for creating and running SQL files are available in the Assignments and Exams page in Blackboard (in the Project 2 group of files). All column headings must show in their entirety. Be sure to include a cover sheet with your full name, section, and date submitted. 19. 4 points...

  • Assume that Flags are 0 and 1. Please note all other assumptions with inline code comments....

    Assume that Flags are 0 and 1. Please note all other assumptions with inline code comments. a. Write a SQL query that will show them one value which represents the number of employees with more than 150 hours accrued vacation. b. Write SQL ONE query that returns two rows: The first is a count of salaried employees with over 125 hours accrued vacation and the second result row is the count of non-salaried employees with over 125 hours accrued vacation....

  • I need help with certain questions. Please. 18. 4 points For each Rental, list the Rental...

    I need help with certain questions. Please. 18. 4 points For each Rental, list the Rental ID, Rental date, customer ID, customer first name, customer last name, and count of disks rented; sort by Rental ID. Show the Rental date formatted as ‘mm-dd-yyyy.’ Hint: use a GROUP BY clause. 19. 4 points List the disk ID, title name, rating, format description, and fee amount for all copies rented in Rental 3; sort by disk ID. Show the fee amount formatted...

  • The Ch07_ConstructCo database stores data for a consultingcompany that tracks all charges to projects. The...

    The Ch07_ConstructCo database stores data for a consulting company that tracks all charges to projects. The charges are based on the hours each employee works on each project. The structure and contents of the Ch07_ConstructCo database are shown in Figure P7.1.Note that the ASSIGNMENT table in Figure P7.1 stores the JOB_CHG_HOUR values as an attribute (ASSIGN_CHG_HR) to maintain historical accuracy of the data. The JOB_CHG_HOUR values are likely to change over time. In fact, a JOB_CHG_ HOUR change will be...

  • This code must be in SQL - Run the script provided with the assignment. This will...

    This code must be in SQL - Run the script provided with the assignment. This will create the tables used for this assignment. Write the necessary SQL commands to perform the required actions. Run the queries to obtain results from the database. (Make sure all columns returned have proper headings.) 3 2 In a single row show the following values: how many unique manufacturers are in the products table. What is the most expensive price per unit in the products...

  • Hello! I'm posting this program that is partially completed if someone can help me out, I...

    Hello! I'm posting this program that is partially completed if someone can help me out, I will give you a good rating! Thanks, // You are given a partially completed program that creates a list of employees, like employees' record. // Each record has this information: employee's name, supervisors's name, department of the employee, room number. // The struct 'employeeRecord' holds information of one employee. Department is enum type. // An array of structs called 'list' is made to hold...

  • SQL Queries – in this assignment you will be asked to create several SQL queries relating...

    SQL Queries – in this assignment you will be asked to create several SQL queries relating to the Sakila database that we installed in class. You may freely use DBeaver to create these queries, but I will expect your solution to show me the SQL code to answer or complete the tasks below. Write a query that produces the last name, first name, address, district, and phone number for every customer in the customer table. (You don’t need to include...

  • Python please help! Thanks you Write a code to get an unlimited number of grades from...

    Python please help! Thanks you Write a code to get an unlimited number of grades from the user (the user can press enter to finish the grades input, or use a sentinel, for example-1), and then calculate the GPA of all the grades and displays the GPA To do this you might need some help. Try to follow the following process (and check your progress by printing different values to make sure they are as they supposed to be): 1-...

  • I am working on multi-table queries for my SQL class using a premade database, which I...

    I am working on multi-table queries for my SQL class using a premade database, which I have included screenshots of. I received assistance and was able to complete a good number of the queries but the bolded ones seem absolutely impossible to do?? How do I write a query for the bolded questions?? I've scoured my textbook and notes and cannot get anything I try to successfully produce results. 1. List all current reservations with the trip ID, customer’s first...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT