Practise: 1. Write A Query To Display All Customers From Mexico As Follows

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

PRACTISE

1. Write a query to display all customers from Mexico as follows

2. Write a query to display all employees that have first name starting with A, by their
ID order.

3. Write a query to display all customers that placed orders in December 1996, by their
contact title order.
4. An order will be taxed 10% if its freight cost is larger than or equal to $100.
Otherwise, an order will be taxed 5% if its freight cost is smaller than $100.
Write a query to show the freight with taxes of orders placed between 20/1/1997 and
31/1/1997 as follows

5. Write a query to display the most expensive product as follows


6. Write a query to display total value of each order from 20/12/1996 to 31/12/1996 as
follows

Note: Total value = sum of all (UnitPrice * Quantity).

7. Write a query to display number of product of each category as follows

8. Write a query to display the categories which has minimum total orders.

9. Write a query to display all product in category 5 as follows

10. Write a query to display all 7-days late orders (an order is called late if it is shipped
after required date), in ascending order of the ID of employee who sale it.
11. Write a query to display all employees that created order from 1 December 1997 to 10
December 1998, by their full name order.

12. In the New Year promotion, from 19/12/1996 to 22/12/1996, a customer from UK
will be discounted 10%, the others will be discounted 5%. Write a query to show
products in order with discount rate as follows

13. Write a query to display product has sold the most in one order.

14. Write a query to display all customers have ordered greater or equal than 40 different
products.

15. Write a query to display number of order of each customer in ‘Spain’ as follows
16. Write a stored procedure named listProduct to display the list of product in a given
category and to calculate the number of different products in this category, where
@categoryName nvarchar(15) is the input parameter and @numberOfProducts int is
the output parameter of this stored procedure.

For example, when we run the following statements, the following list will be displayed in
Results tab and 12 will be displayed in Messages tab:
Declare @x int
Exec listProduct ‘Beverages’, @x output
Print @x

17. Create a stored procedure named listOrder to display the list of orders done by a given
employee during a period of time and calculate the number of these orders, when
@firstName nvarchar(10), @lastName nvarchar(20), @fromDate date, @toDate date
are input parameters and @numberOfOrders int is output parameter of this stored
procedure.

For example, when we run the following statements, the following list will be displayed in
Results tab and 5 will be displayed in Messages tab:
Declare @x int
Exec listOrder ‘Nancy’, ‘Davolio’, ‘1996-08-01’, ‘1996-08-30’, @x output
Print @x

You might also like