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

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?
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?
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.
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...
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?
What is the syntax of a typical DOCTYPE declaration you would find in an XML document...
What is the syntax of a typical DOCTYPE declaration you would find in an XML document if its DTD is located in the same directory as the XML document itself?
5.A survey of 15 randomly selected employees from Bob’s factory was taken to find out how...
5.A survey of 15 randomly selected employees from Bob’s factory was taken to find out how many sick days they took due to colds and flu last year. Suppose Bob didn’t take a random sample. Suppose the employees in the sample were those who responded to an advertisement Bob put out to the whole company, looking for volunteers to participate in the survey. What kind of error would be made here? THERE IS ONLY ONE CORRECT ANSWER – CHECK YOUR...
Please answer as many as possible. Thanks! 1. How does syntax allow a person to know...
Please answer as many as possible. Thanks! 1. How does syntax allow a person to know the meaning of a combination of words he has never heard before such as "The pink hippopotamus flipped backward over the yellow duck?" a. by knowing what relational meaning between the words mean when they occur in that order b. by knowing what each word in the sentence means c. by having heard each of the words in other contexts and generalizing to the...
Question #10: What is the basic character for RC circuit? In other words, how do the...
Question #10: What is the basic character for RC circuit? In other words, how do the current and voltage change with time? What about the discharging? What is the time constant? How to compute it? How to compute the time constant. How does the charge capacitor change with respect to time?
Write SQL queries for the following statements based on Employees table whose schema is given below:...
Write SQL queries for the following statements based on Employees table whose schema is given below: (Employee_ID,First_Name,Last_Name,Email,Phone_Number,Hire_Date,Job_ID,Salary, Manager_Id, Department_Id) a. Create the given table along with the following constraints: Phone_Number should not be left undefined, salary should be between 10000 and 20000, employee_id should uniquely identify rows and should not be left undefined. User-defined names should be given to constraints. b.  Display each employee’s last name, hire date and salary review date (which is the date after six months of service)....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT