0% found this document useful (0 votes)
4 views5 pages

SQL Questions

The document outlines a series of SQL tasks related to data retrieval, insertion, and updates across various tables including DimCustomer, FactInternetSales, and newly created tables like Employees, Customers, Products, Orders, Departments, and Projects. It includes commands for selecting, updating, and inserting records, as well as creating new tables with specified columns and constraints. Additionally, it details operations such as ordering results, calculating averages, and altering table structures.

Uploaded by

redundantfree
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
4 views5 pages

SQL Questions

The document outlines a series of SQL tasks related to data retrieval, insertion, and updates across various tables including DimCustomer, FactInternetSales, and newly created tables like Employees, Customers, Products, Orders, Departments, and Projects. It includes commands for selecting, updating, and inserting records, as well as creating new tables with specified columns and constraints. Additionally, it details operations such as ordering results, calculating averages, and altering table structures.

Uploaded by

redundantfree
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 5

1. Retrieve all columns from the DimCustomer table.

2. Select the FirstName and LastName columns then using these two column
create Full Name with “-” between firstname and LastName from
the DimCustomer table.
3. Retrieve the top 10 rows from the FactInternetSales table.
4. Select distinct ProductKey values from the FactInternetSales table.
5. Retrieve all columns from the DimProduct table where the ProductKey is
310.
6. Select the EnglishProductName and StandardCost from
the DimProduct table.
7. Retrieve the top 5 most expensive products based on StandardCost from
the DimProduct table.
8. Select all columns from the DimGeography table where
the CountryRegionCode is 'US'.
9. Retrieve the SalesOrderNumber and SalesAmount from
the FactInternetSales table.
10.Select distinct CurrencyKey values from the FactCurrencyRate table.

11. Retrieve distinct CustomerKey values from


the FactInternetSales table.
12. Retrieve distinct OrderDate values from
the FactInternetSales table.
13. Retrieve the top 5 customers with the
highest YearlyIncome from the DimCustomer table.
14. Select the top 10 products with the lowest StandardCost from
the DimProduct table.
15. Retrieve the top 3 SalesAmount values from
the FactInternetSales table.
16. Retrieve all columns from the DimCustomer table and order the
results by LastName in ascending order.
17. Select EnglishProductName and StandardCost from
the DimProduct table and order the results by StandardCost in
descending order.
18. Retrieve SalesOrderNumber and SalesAmount from
the FactInternetSales table and order the results by SalesAmount in
ascending order.
19. Retrieve FirstName, LastName, and YearlyIncome from
the DimCustomer table and order the results by YearlyIncome in
descending order
20. Insert a new record into the DimCurrency table with the
following values: CurrencyKey = 100, CurrencyName = 'Test Currency'.
21. Insert a new record into the DimProduct table with the following
values: ProductKey = 1000, EnglishProductName = 'Test
Product', StandardCost = 50.00.
22. Insert a new record into the DimCustomer table with the
following values: CustomerKey = 10000, FirstName = 'John', LastName =
'Doe'.
23. Insert a new record into the DimGeography table with the
following values: GeographyKey = 1000, City = 'Test
City', CountryRegionCode = 'US'.
24. Update the StandardCost of the product with ProductKey = 310 to
25.00 in the DimProduct table.
25. Update the YearlyIncome of the customer with CustomerKey =
11000 to 75000.00 in the DimCustomer table.
26. Update the SalesAmount of the record with SalesOrderNumber =
'SO12345' to 200.00 in the FactInternetSales table.
27. Update the CurrencyName of the currency with CurrencyKey =
100 to 'Updated Currency' in the DimCurrency table.
28. Update the City of the geography with GeographyKey = 1000 to
'Updated City' in the DimGeography table.
29. Retrieve the top 5 customers with the
highest YearlyIncome from the DimCustomer table and order the
results by YearlyIncome in descending order.
30. Select distinct ProductKey values from the FactInternetSales table
and order the results by ProductKey in ascending order.
31. Select distinct OrderDate values from the FactInternetSales table
and order the results by OrderDate in ascending order and
SalesAmount in descending order.
32. Retrieve the top 3 StandardCost values from
the DimProduct table and order the results by StandardCost in
descending order.
33. Retrieve the FirstName, LastName, and YearlyIncome of
customers whose YearlyIncome is greater than 100000 from
the DimCustomer table.
34. Select the EnglishProductName and StandardCost of products
where the StandardCost is less than 50 from the DimProduct table.
35. Retrieve the SalesOrderNumber and SalesAmount of sales where
the SalesAmount is greater than 1000 and less than 3000 from
the FactInternetSales table.
36. Select distinct ProductKey values from the FactInternetSales table
where the OrderDate is after '2022-01-01'.
37. Retrieve the top 5 SalesAmount values from
the FactInternetSales table where the ProductKey is 310.
38. Retrieve the total SalesAmount from the FactInternetSales table.
39. Select the average StandardCost from the DimProduct table.
40. Retrieve the maximum YearlyIncome from
the DimCustomer table.
41. Select the minimum OrderDate from the FactInternetSales table.
42. Retrieve the count of distinct CustomerKey values from
the FactInternetSales table.
43. Retrieve the top 10 customers with the highest
total SalesAmount from the FactInternetSales table.
44. Select the EnglishProductName and StandardCost of products that
have never been sold (not in FactInternetSales).
45. Retrieve the FirstName, LastName, and total SalesAmount for
each customer from the DimCustomer and FactInternetSales tables.
46. Update the StandardCost of all products in the DimProduct table
by increasing it by 10%.
47. Insert a new record into the FactInternetSales table with
a SalesAmount that is the average of all SalesAmount values in the
table.
48. Retrieve the SalesOrderNumber and SalesAmount for sales that
occurred in the year 2022.
49. Select the EnglishProductName and StandardCost of products that
have a StandardCost greater than the average StandardCost.
50. Retrieve the FirstName, LastName, and YearlyIncome of
customers who have made at least one purchase (exists
in FactInternetSales).
51. Update the YearlyIncome of customers who have made
purchases with a SalesAmount greater than 1000.
52. Retrieve the top 5 SalesTerritoryRegion values with the highest
total SalesAmount

Apart from Adventure works table.

Task 61: Employees Table

1. Create a table named Employees with the following columns:


o EmployeeID (Primary Key, auto-increment, default
prefix EM followed by a sequence number, e.g., EM0001)
o FirstName (VARCHAR)
o LastName (VARCHAR)
o HireDate (DATE, default current date)
o Salary (DECIMAL, default 50000.00)

Insert 3 rows into the Employees table.

Task 62: Customers Table

2. Create a table named Customers with the following columns:


o CustomerID (Primary Key, auto-increment, default
prefix CU followed by a sequence number, e.g., CU0001)
o CustomerName (VARCHAR)
o JoinDate (DATE, default current date)
o IsActive (BOOLEAN, default TRUE)
Insert 5 rows into the Customers table.

Task 63: Products Table

3. Create a table named Products with the following columns:


o ProductID (Primary Key, auto-increment, default
prefix PR followed by a sequence number, e.g., PR0001)
o ProductName (VARCHAR)
o Price (DECIMAL, default 10.00)
o CreatedOn (DATE, default current date)

Insert 6 rows into the Products table.

Task 64: Orders Table

4. Create a table named Orders with the following columns:


o OrderID (Primary Key, auto-increment, default
prefix OR followed by a sequence number, e.g., OR0001)
o CustomerID (INT, Foreign Key referencing Customers)
o OrderDate (DATE, default current date)
o TotalAmount (DECIMAL, default 0.00)

Insert 5 rows into the Orders table.

Task 65: Departments Table

5. Create a table named Departments with the following columns:


o DepartmentID (Primary Key, auto-increment, default
prefix DE followed by a sequence number, e.g., DE0001)
o DepartmentName (VARCHAR)
o CreatedOn (DATE, default current date)

Insert 10 rows into the Departments table.

Task 66: Projects Table

6. Create a table named Projects with the following columns:


o ProjectID (Primary Key, auto-increment, default
prefix PJ followed by a sequence number, e.g., PJ0001)
o ProjectName (VARCHAR)
o StartDate (DATE, default current date)
o IsCompleted (BOOLEAN, default FALSE)

Insert 10 rows into the Projects table.

--Alter the ProjectName column name to Proj_nm (rename)


--Alter ProjectName column datatype to nvarchar.
--Add one column in the table Proj_dept with datatype nvarchar and make
default value as “BI”

-- Add one column in the table Is_active with datatype Boolean ( value as
0 and 1)

--Drop the column IsCompleted .

--Update the Proj_nm column value to ‘COZ_’[Proj_nm]’.

-- Update the Is_active column value to 1 if the column value is 0 and vice
versa.

You might also like