Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 9

PT.

IFS Solusi Integrasi

PT Haluan Rekadaya Konsultindo


Applicant Name: Cody Herry_____________________________________________________________
Evaluation Date: 24 Mei 2022__________________________________________________________
Contact Number: 082352878116________________________________________________________

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 Table: branch_category


Branch_id Branch_name Branch_Category Category_Id Name
P0001 Jakarta 1 1 Primary
P0002 Medan 2 Secondary
P0003 Makasar 2

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.

1. Create statement to add the following sales,


Sales Id: E0005, Sales Name: Darryl, Join Date: current date, Manager: E0002
Ans :
INSERT INTO sales (Sales_Id, Sales_Name, join_date, Manager) VALUES ('E0005','Darryl
',date_format(curdate(), '%m-%d-%Y'),' E0002');
2. Create SELECT statement to get list of all sales with their current branch.
Expected Result:

Sales Id Sales Name Branch Id Branch Name Category


E0001 Ganesha P0001 Jakarta Name
Primary
E0002 Felicia P0002 Medan -
E0003 Calista P0003 Makasar Secondary
E0004 Wiwid - - -
(Please notice that for resigned employee E0004, is still displayed but WITHOUT Branch Id, Branch Name
and Category information )
Ans :
SELECT ba.sales_id 'Sales Id',
s.Sales_Name 'Sales Name',
IF (ba.valid_to IN('01/01/2999'), ba.Branch_id, '') 'Branch Id',
IF (ba.valid_to IN('01/01/2999'), b.Branch_Name, '') 'Branch Name',
IF (ba.valid_to IN('01/01/2999'), bc.Name, '') 'Category'
FROM branch_assignment ba
LEFT JOIN sales s ON s.Sales_Id = ba.Sales_Id
LEFT JOIN branch b ON b.Branch_id = ba.Branch_id
LEFT JOIN branch_category bc ON bc.Category_Id = b.Branch_Category;

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;

4. Select 1 from sales where 1=1 ; will result:


Ans :
5 Row with value 1;
5. Select * from sales where 1=2; will result:
Ans :
Nothing

6. Select * from branch where branch_id = ‘P00%’; will result:


Ans :
Nothing

7. Select * from branch where branch_id like ‘P00%’; will result:


Ans :
3 Data from branch table that Branch_id begin with P00

8. Define keys for each table above


Ans :
sales.Sales_Id PK
branch.Branch_Id PK
branch_category.Category_Id PK
branch.Branch_Category FK
branch_assignment.Sales_Id FK
branch_assignment.Brand_Id FK

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:

1. Display the sum of sales amount for each sales name


Ans :
SELECT sum(st.Sales_Amount) 'Sales Amount',
(SELECT Sales_Name FROM sales WHERE Sales_Id = st.Sales_Id) 'Sales Name'
FROM sales_transaction st
GROUP BY Sales_Id;

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

1. Create function to display the following pattern

*
**
***
****
*****
******
*******
********
*********
**********
Ans :
public static void triangle(int input) {

for (int i = 1; i <= input; i++) {


for (int j = input; j >= 1 ; j--) {
if (i<j) {
System.out.print(" ");
}else {
System.out.print("*");
}
}System.out.println();
}
}

public static void main(String[] args) {


triangle(10);
}
2. Create function for checking prime number, return true for prime, false for not prime
Note: Prime Number is 2,3,5,7,11,13, etc
Example: isPrime(3) return true; isPrime(4) return false;
Ans :
public static Boolean isPrime(int input) {
Boolean retval = true;

if (input == 2) {
return retval;
}

if (input%2 != 1 || input == 0 || input == 1) {


retval = false;
}

return retval;
}

public static void main(String[] args) {


System.out.println(isPrime(4));
}

3. You have the following string:


String str = “IFS Solusi Integrasi, PT”; // syntax in java
Use your programming logic to find how many i (or I) in the string.
The Result: 4
Ans :
public static int cekIAlphabet(String input) {
int retval = 0;
char checkVar = 'i';
for (int i = 0; i < input.length(); i++) {
if (Character.compare(checkVar, input.charAt(i)) == 0) {
retval++;
}
}
return retval;
}
public static void main(String[] args) {
String str = "IFS Solusi Integrasi, PT";
System.out.println(cekIAlphabet(str.toLowerCase()));
}
4. You have array of integer
int[] anArray = { 8,20,50,33,89,35,23,90,101,77,23 }; //syntax in java
Use your programming logic to find the greatest integer in that array and display the result
Note: you could use any programming language you’ve known.
The Result: 101
Ans :
public static int checkGreatestNumberInArray(int[] input) {
int retval = 0;

for (int i = 0; i < input.length; i++) {


if (input[i]>retval) {
retval = input[i];
}
}

return retval;
}

public static void main(String[] args) {


int[] anArray = { 8,20,50,33,89,35,23,90,101,77,23 };
System.out.println(checkGreatestNumberInArray(anArray));
}

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;
}

for (int i = 2; i < input; i++) {


temp = previous + current;
previous = current;
current = temp;

retval += temp;
}
return retval;
}

public static void main(String[] args) {

System.out.println(sumFibonacciNumber(5));
}

You might also like