In the northwind database and orders table, select the ShipCountry, ShipVia, and EmployeeID as a group and compute the count as Total. The group can only include where the ShipVia is less than the EmployeeID and either ShipCountry does not end in "y" or "%%l" or EmployeeID = 4. The grouping total must be greater than 7 and sort by total descending.
USE northwind; #Selected the database northwind
SELECT COUNT(*) AS 'Total' #Calculating the count and giving it the tab Total
FROM orders #From the table orders
WHERE (ShipVia < EmployeeID) AND (SUBSTRING(ShipCountry, -1) != 'y' OR SUBSTRING(ShipCountry, -3) != '%%l' OR EmployeeID = 4) #The conditions as mentioned in the question
GROUP BY ShipCountry, ShipVia, EmployeeID #Grouped by on the columns mentioned in the question
HAVING Total > 7 #Applying the clause where the count is required to be greater than 7
ORDER BY Total DESC; #Ordered the results by Total column that we created in descending order
There isn't much to explain over here. This entire question is a combination of the basic tools in SQL nothing more than that. If you have any specific doubts do let me know I will add it to the answer. Regards.
Get Answers For Free
Most questions answered within 1 hours.