Professional Documents
Culture Documents
TEST AE - Cody Herry
TEST AE - Cody Herry
SQL
The following question will evaluate your knowledge about SQL Query and Data Manipulation Language
(DML); use any database syntax you’ve known
Table: sales
Sales_Id Sales_Name join_date(MM-DD-YYYY) Manager
E0001 Ganesha 02/18/2000 *
E0002 Felicia 08/01/2002 E0001
E0003 Calista 05/10/2003 E0001
E0004 Wiwid 04/06/2006 E0002
Table: branch_assignment
Sales_Id Branch_id valid_from(MM/DD/YYYY) valid_to(MM/DD/YYYY)
E0001 P0001 02/18/2000 01/01/2999
E0002 P0002 08/01/2002 01/01/2999
E0003 P0003 05/10/2003 01/01/2999
E0004 P0001 04/06/2006 01/01/2010
Note : Year 2999, states that the employees are still working in the company, and year 2010 states that
employee has been resigned.
3. Create SELECT statement to get the list of all sales and their manager name.
Sales Id Sales Name Manager Id Manager Name
E0001 Ganesha *
E0002 Felicia E0001 Ganesha
E0003 Calista E0001 Ganesha
E0004 Wiwid E0002 Felicia
E0005 Darryl E0002 Felicia
Ans :
SELECT s.Sales_Id 'Sales Id',
s.Sales_Name 'Sales Name',
s.Manager 'Manager Id',
(SELECT Sales_Name from sales where sales_id = s.Manager)
FROM sales s;
9. Draw ERD diagram for these tables: sales , branch, branch_category, branch_assignment and
sales_transaction
Ans :
10. Define any validation needed to prevent invalid data is entered to table branch_assignment
Ans :
Sales_Id and Branch_Id must be foregin key, look up to primary key
Valid_from and valid_to format date must be (MM/DD/YYYY)
Valid_from Not null
Valid_to as default set to 01/01/2999
Table: sales_transaction
id Sales_Id Sales_Amount Sales_Date(MM/DD/YYYY)
1 E0001 32000 3/1/2010
2 E0002 20000 3/1/2010
3 E0003 40000 3/1/2010
4 E0004 30000 3/1/2010
5 E0001 33000 4/1/2010
6 E0002 21000 4/1/2010
7 E0003 42000 4/1/2010
8 E0004 20000 4/1/2010
9 E0001 34000 5/1/2010
10 E0002 11000 5/1/2010
11 E0003 22000 5/1/2010
12 E0004 55000 5/1/2010
13 E0001 6000 6/1/2010
14 E0002 7000 6/1/2010
15 E0003 8000 6/1/2010
16 E0004 9000 6/1/2010
17 E0001 66000 7/1/2010
18 E0002 11000 7/1/2010
19 E0003 32000 7/1/2010
20 E0004 12000 7/1/2010
21 E0001 34000 8/1/2010
22 E0002 11000 8/1/2010
23 E0003 22000 8/1/2010
24 E0004 55000 8/1/2010
Write SELECT Statement to get the result:
2. Who has the maximum sales amount, how much and on what date.
Ans :
SELECT (SELECT Sales_Name FROM sales WHERE Sales_Id = st.Sales_Id) 'Sales Name',
st.Sales_Date
FROM sales_transaction st
WHERE st.Sales_Amount = (SELECT max(Sales_Amount) from sales_transaction);
3. Who has the maximum sales amount on each month and how much.
Ans :
SELECT (SELECT Sales_Name FROM sales WHERE Sales_Id = st.Sales_Id) 'Sales Name',
Sales_Amount
FROM sales_transaction st
WHERE st.Sales_Amount IN (SELECT max(Sales_Amount) from sales_transaction GROUP BY
MONTH(Sales_Date));
Programming
The following question will evaluate your logic programming; use any programming language you’ve
known
*
**
***
****
*****
******
*******
********
*********
**********
Ans :
public static void triangle(int input) {
if (input == 2) {
return retval;
}
return retval;
}
return retval;
}
5. Create function to calculate sum of Fibonacci Number based on requested sequence length.
Fibonacci Number is a simple series of numbers in which the sequence of numbers is the sum
of two numbers.
Ex: Input=7
Fibonacci Number = 0,1,1,2,3,5,8.
The Result = 20
Ans :
public static int sumFibonacciNumber(int input) {
int previous = 0;
int current = 1;
int temp = 0;
int retval = 1;
if (input == 0 || input == 1) {
return 0;
}
retval += temp;
}
return retval;
}
System.out.println(sumFibonacciNumber(5));
}