Question

In: Computer Science

SQL Question: What syntax to find the following? Out of the 10 employees, how many do...

SQL Question:

What syntax to find the following? Out of the 10 employees, how many do we have a record of handling at least one order? You can do this by pulling the distinct employee ids from the Order table

What syntax would you use to pull a list of all Shipper IDs and Names along with the count of all orders they’ve shipped? Make sure rename count(orders) to OrdersShipped. To do this you’ll need to join Orders and Shippers and then “group by ShipperID, ShipperName”. What syntax did you use?

Solutions

Expert Solution

/* The solution for the given first SQL statement is: */

SELECT DISTINCT employee_id  
FROM Orders; 
--Using the distinct keyword we can get the distinct values of a column


/* The solution fro the second SQL statement is: */

/* Step-1: Initially select the ShipperID,ShipperName from Shippers table
Along with this we have to use COUNT keyword to display the count of orderID's
And for our convenience we will rename it y aliasing it as OrdersShipped */

/* Step-2: Selecting from the Orders table*/

/* step-3: As we need details from only the Orders table and not from Shippers we use LEFT JOIN*/

/* step-4: Connecting the both tables using the ShipperID */

SELECT Shippers.ShipperID,Shippers.ShipperName,COUNT(Orders.OrderID) AS OrdersShipped 
FROM Orders                                        
LEFT JOIN                                          
Shippers ON Orders.ShipperID = Shippers.ShipperID  
GROUP BY ShipperName;                              

/* step-5: To group the results based on ShipperName */

  


Related Solutions

Using SQL, answer the following question referring to the table below How many twins are there?...
Using SQL, answer the following question referring to the table below How many twins are there? (Just having the same birthday does not make you twins.) Name the twins. CREATE TABLE IF NOT EXISTS students ( student_id INT NOT NULL AUTO_INCREMENT, first_name VARCHAR(16), last_name VARCHAR(24), birthday DATE, street_address VARCHAR(128), city VARCHAR(32), PRIMARY KEY (student_id)); INSERT INTO students (first_name, last_name, birthday, street_address, city) VALUES ('John','Jones','2000-12-17','250 Pines Blvd.','Pembroke Pines'), ('Mark','Bacon','2000-04-12','1270 Walnut St.','Prarie Bluff'), ('Bill','Carlson','1999-07-06','250 Pines Blvd.','Pembroke Pines'), ('Jean','Carlson','1999-07-06','250 Pines Blvd.','Pembroke Pines'), ('Leonard','Cook','2000-09-14','8046...
SQL Program True/False Question 1. Which of the following is true of a many to many...
SQL Program True/False Question 1. Which of the following is true of a many to many relationship? T/F 2. Security is rarely a concern for most databases. T/F 3. A security requirement refers to the need to restrict who can access some of the database data. T/F 4. Report requirements refer to the input forms the database will need. T/F 5. Insert permission is the permission to add records to the database. T/F 6. A trigger is code usually written...
C++ : Find the syntax errors in the following program. For each syntax error, fix it...
C++ : Find the syntax errors in the following program. For each syntax error, fix it and add a comment at the end of the line explaining what the error was. #include <iostream> #include <cmath> using namespace std; int main(){ Double a, b, c; 2=b; cout<<"Enter length of hypotenuse"<<endl; cin>>c>>endl; cout>>"Enter length of a side"<<endl; cin>>a; double intermediate = pow(c, 2)-pow(a, 2); b = sqrt(intermediate); cout<<"Length of other side is:" b<<endline; return 0; }
How many ways are there to choose 5 out of 10 homebuyers and 3 out of...
How many ways are there to choose 5 out of 10 homebuyers and 3 out of 8 realtors and have them stand in a line so that realtors do not stand next to each other?
Develop SQL statements to do the following: Query 1: List all employees by LXXX_EMP_ID, LXXX_EMP_NAME, LXXX_EMP_CITY,...
Develop SQL statements to do the following: Query 1: List all employees by LXXX_EMP_ID, LXXX_EMP_NAME, LXXX_EMP_CITY, LXXX_EMP_PHONE, LXXX_DEP_ID, order by LXXX_DEP_ID. Query 2: List all employees by LXXX_EMP_ID, LXXX_EMP_NAME, LXXX_DEP_NAME, order by LXXX_DEP_NAME. Query 3: List all employees by LXXX_EMP_ID, LXXX_EMP_NAME, LXXX_DEP_NAME who work for the "XXX_SALES" department. Query 4: List all employees by LXXX_EMP_ID, LXXX_EMP_NAME, LXXX_DEP_NAME, LXXX_EMP_CITY, LXXX_DEP_CITY who live and work in the same city, order by LXXX_DEP_CITY Query 5: List all employees by LXXX_EMP_ID, LXXX_EMP_NAME, LXXX_PROJ_TYPE, LXXX_START_DATE,...
A department contains 10 part-time employees and 15 full-time employees. In how many ways can a...
A department contains 10 part-time employees and 15 full-time employees. In how many ways can a committee be formed with 6 members if it must have more full-time employees than part-time employees?
Thoroughly discuss and answer the following question. Do some research and find out whether Babbage’s Analytical...
Thoroughly discuss and answer the following question. Do some research and find out whether Babbage’s Analytical Engine is a computer according to the von Neumann model. Post a complete answer to the best of your abilities and research and understanding. Reference your sources other than textbook.
Many employers are monitoring employees to see how many and what types of phone calls they...
Many employers are monitoring employees to see how many and what types of phone calls they are making. Some companies also monitor emails employees send and receive and websites they access. In your initial discussion post, respond to the following questions: How might a company benefit from gathering this type of information? Why might employees object to being monitored? Do you think this type of monitoring is appropriate or inappropriate, from a security perspective? Explain your answer.
A student is to answer 8 out of 10 questions on an exam. (i) How many...
A student is to answer 8 out of 10 questions on an exam. (i) How many choices has (s)he? How many choices if (s)he must answer the first 3 questions? How many if (s)he must answer at least 4 of the first five questions?
Write and run SQL statements to complete the following tasks Show the details of the employees...
Write and run SQL statements to complete the following tasks Show the details of the employees who are located in area code 901 and their manager employee number is 108. Show the details of the employees who are also mangers. Show the details of the customers whose balance is greater than 220 but less than 500. Show the details of the customers whose balance is highest. Show customer 10014’s name and the product’s descriptions which he/she purchased and the number...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT