JAVA interview questions on Strings
Following are few examples of questions that are frequently asked in interviews
1. String operations
Multiple choice questions , where output of a code sample can be asked mostly involves
questions on string operations like concatenation, reversing, sub-string calculation etc.
Ex:
What is the output of this expression
"Was it a car or a cat I saw?".sub-string(9, 12)
Sub-string of the above string starts from 9th character starting from 0 and ends at character 12,
including spaces . i.e starts with c and ends with r. Therefore, the output will be car.
2. Reverse a string without using builtin functions.
This is very simple when we use the builtin function .reverse provided by strings
The below example explains how the same can be done without using built in reverse function.
The logic is to Initiate an empty String “”. While iterating the input String from the back
,Construct the output reversed,with char by char concatenation using operator +
public static void main(String a[]){
String original, reverse = "";
Scanner sc = new Scanner(System.in);
System.out.println("Enter a string ");
original = sc.nextLine();
int length = original.length();
for ( int i = length - 1; i >= 0; i-- )
reverse = reverse + original.charAt(i);
System.out.println("reversed string "+reverse);
Output:
Enter a string
matrix
reversed string xirtam
3. Check if a given string is palindrome without using built in
reverse function
This program can be asked as an extension to above program, From the above we have already
seen how to reverse a string
Using .equals method by the String class we check if the String and the reversed String are equal.
public static void main(String a[]){
String original, reverse = "";
Scanner sc = new Scanner(System.in);
System.out.println("Enter a string ");
original = sc.nextLine();
int length = original.length();
for ( int i = length - 1; i >= 0; i-- )
reverse = reverse + original.charAt(i);
if (original.equals(reverse))
System.out.println("palindrome");
else
System.out.println(" not a palindrome.");
output:
Enter a string to check if it is a palindrome
madam
Entered string is a palindrome.
4. Why is string called as immutable?
String is immutable in Java. An immutable class is simply a class whose instances cannot be
modified. All information in an instance is initialized when the instance is created and the
information can not be modified. There are many advantages of immutable classes.
Security: parameters are typically represented as String in network connections, database
connection urls, usernames/passwords etc. If it were mutable, these parameters could be easily
changed.
Synchronization and concurrency: making String immutable automatically makes them thread
safe thereby solving the synchronization issues.
Caching: when compiler optimizes your String objects, it sees that if two objects have same
value (a="test", and b="test") and thus you need only one string object (for both a and b, these
two will point to the same object).
Class loading: String is used as arguments for class loading. If mutable, it could result in wrong
class being loaded (because mutable objects change their state).
5. How to find duplicate characters in a string and the number of
occurences of each
This is also a very popular coding question on the various level of Java interviews and written
test, where you need to write code. On difficulty level, this question is at par with palindrome
string.
Though we have discussed a simialr question on arrays,using nested loops. doing it on string also
works the same way when we treat string as an array of characters(letters).
But we will see another model where we use Map/HashMap to find the duplicates.
This model will also allow you to get familiar with the concept of Map data structure, which
allows you store mappings in the form of key and value.
Here is how the code looks like:(we are using combination as direct input, same can be replced
with reading string from console.)
public static void main(String args[])
printDuplicateCharacters("Combination");
public static void printDuplicateCharacters(String str)
HashMap<Character, Integer> Duplicates = new HashMap<Character, Integer>();
char[] charsArray = str.toCharArray();
for(int i=0;i<charsArray.length;i++){
char ch=charsArray[i];
if(Duplicates.containsKey(ch)){
System.out.println("Duplicate character "+ch);
Duplicates.put(ch, Duplicates.get(ch)+1);
} else {
Duplicates.put(ch, 1);
System.out.println("occurences of each duplciate charcater:");
Set<Character> keys = Duplicates.keySet();
for(Character ch:keys){
if(Duplicates.get(ch) > 1){
System.out.println(ch+"--->"+Duplicates.get(ch));
The idea here is simple. While adding each character of the string to a hashmap,If the hash map
already have any character of the string we simply consider it as duplicate.
Hashmap we used is of type <Character, Integer> which means the key of the map is a character
and the value is an integer, that strores the count
the output for above program which is finding duplicates for the string
“combination” looks like:
Duplicate character i
Duplicate character o
Duplicate character n
occurences of each duplciate charcater:
n--->2
o--->2
i--->2
We use a second data structure set, just to print the stored count of each character. If the question
is just to find the duplicates, then we can just avoid the second part.
6. Count the number of vowels and consonants in a string
A simple basic level question which can be solved using the concept of character comparison.
The code for the program looks like below:
public static void main(String[] args) {
String input = "This is a test string";
int vowels = 0, consonants = 0;
input = input.toLowerCase();
for(int i = 0; i < input.length(); ++i)
char ch = input.charAt(i);
if(ch == 'a' || ch == 'e' || ch == 'i'
|| ch == 'o' || ch == 'u') {
++vowels;
else if((ch >= 'a'&& ch <= 'z')) {
++consonants;
System.out.println("Vowels: " + vowels);
System.out.println("Consonants: " + consonants);
The logic here is very simple. We first convert the string to lowercase to avoid comparison twice
for uppercase and lowercase letters. We iterate through each char of the string and compare it
with the vowel letters. If not an vowel we add it to consonants count.
The character equals method compares the ASCII code of the character to match the input char .
We should note that spaces are also treated as chars and hence in else loop we are verifying
whether it is an alphabet.
output:
Vowels: 5
Consonants: 12
AVA String and Array concepts
The array is one of the fundamental data structures in java , Array based questions are quite
popular on Java interviews. We have also discussed JAVA interview questions on Arrays
and Strings in this blog.
There are two types of questions we commonly find on arrays
1. Those based on the concept of Arrays in Java
2. And those which are based upon how to use arrays in problem solving
Most questions in this topic will be based on concept of arrays without much code involved.
Before we get to examples, let us look at some of the basic concepts and terms involved in this
concept.
Changing size of array in JAVA
Once an array is created, it cannot be resized. For dynamic implementation of array, using
arrayLists is a suggested option. Arrays are fixed memory blocks.
Array storage in JAVA
Array is created in heap space of JVM memory. Since array is object in Java, even if you create
array locally inside a method or block, object is always allocated memory from heap.
ArrayStore Exception in JAVA
ArrayStoreException is a run time exception which occurs when you try to store non-compatible
element in an array object. The type of the elements must be compatible with the type of array
object. For example, you can store only string elements in an array of strings. if you try to insert
integer element in an array of strings, you will get Array Store Exception at run time.
Anonymous array in JAVA
Anonymous array is an array without reference. For example,
System.out.println(new int[]{1, 2, 3, 4, 5}.length);
The array inside the print statement is created without any reference object.
Array Index Out Of Bounds Exception in JAVA
It is a run time exception which occurs when your program tries to access invalid index of an
array i.e negative index or index higher than the size of the array.
JAVA interview questions on Arrays
Iterating over an array in JAVA
Example: Consider the following example to understand the problem
You iterate an array based on index.
Below is the example of code which iterates and prints the content of array
In the below code, we declared an array a.
Using an index i we accessed the content of the array at that specific index. (Note that i starts at
0)
Note we start at i=0 and end at i<a.length
public static void main(String[] args)
int[] a = new int[]{45, 12, 78, 34, 89, 21};
for (int i = 0; i < a.length; i++)
System.out.println(a[i]);
Reading input for an array and display the elements by iterating
over an array
It is important to note java provides different ways to read input like BufferedReader with subtle
differences. Scanner is one of them.
We declared the array of size n.
Got the input from keyboard and Printed it on to console.
We saw here how array is filled and printed out. Note array is mutable.
public static void main(String args[])
Scanner sc = new Scanner(System.in);
System.out.println("enter size of array");
int n = sc.nextInt();
int array[] = new int[n];
System.out.println("enter elements");
for(int i=0;i<n;i++){ //for reading elements into array
array[i] = sc.nextInt();
}
for(int i=0;i<n;i++) //for displaying elements in an array
System.out.println(array[i]);
Multi dimension arrays
A multi-dimensional array of size m x n can be considered as a table of
elements with m rows and n columns Simply it can be considered as a
matrix of order m x n where m and n are number of rows and columns
respectively
JAVA Interview Questions on Programs and Answers
Sample Programs asked for in interviews and technical tests
Find the sum/difference of two matrices given that matrices are of same order
Below is the program for addition of two matrices.
Declare matrix A of m rows and n columns.
Read matrix Data into matrices/ 2D arrays using Scanner class.
Add matrix A and B to C. You can check a example run of the program at the end.
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter number of rows m: ");
int m = sc.nextInt();
System.out.print("Enter number of columns n: ");
int n = sc.nextInt();
int[][] a = new int[m][n];
int[][] b = new int[m][n];
System.out.println("enter the elements of matrix 1");
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
a[i][j] = sc.nextInt();
System.out.println("enter the elements of matrix 2");
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
b[i][j] = sc.nextInt();
int[][] c = new int[m][n];
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
c[i][j] = a[i][j] + b[i][j];
System.out.println("the sum of the two matrices is");
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
System.out.print(c[i][j] + " ");
System.out.println();
output:
Enter number of rows m: 3
Enter number of columns n: 3
Enter the first matrix
123456789
Enter the second matrix
345678912
The sum of the two matrices is
468
10 12 14
16 9 11
2. Sort an array of integers
The below algorithm we use is the bubble sort.
It sorts by repeatedly swapping the adjacent elements if they are in wrong order.
Best way to learn this type of programs is take pen and paper and go through,
public static void main(String[] args)
Scanner sc=new Scanner(System.in);
System.out.println("enter size of array");
int n=sc.nextInt();
int arr[]=new int[n];
System.out.println("enter elements");
for(int i=0;i<n;i++){//for reading array
arr[i]=sc.nextInt();
int temp; // for swapping
for (int i = 0; i < n; i++)
{
for (int j = i + 1; j < n; j++)
if (arr[i] > arr[j])
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
System.out.print("Sorted Array : ");
for (int i = 0; i < n ; i++)
System.out.print(arr[i] + " ");
}
Example:
First Pass:
( 5 1 4 2 8 ) –> ( 1 5 4 2 8 ), Here, algorithm compares the first two elements, and swaps since 5
> 1.
( 1 5 4 2 8 ) –> ( 1 4 5 2 8 ), Swap since 5 > 4
( 1 4 5 2 8 ) –> ( 1 4 2 5 8 ), Swap since 5 > 2
( 1 4 2 5 8 ) –> ( 1 4 2 5 8 ), Now, since these elements are already in order (8 > 5), algorithm
does not swap them.
Second Pass:
( 1 4 2 5 8 ) –> ( 1 4 2 5 8 )
( 1 4 2 5 8 ) –> ( 1 2 4 5 8 ), Swap since 4 > 2
( 1 2 4 5 8 ) –> ( 1 2 4 5 8 )
( 1 2 4 5 8 ) –> ( 1 2 4 5 8 )
Now, the array is already sorted, but our algorithm does not know if it is completed. The
algorithm needs one whole pass without any swap to know it is sorted.
Third Pass:
( 1 2 4 5 8 ) –> ( 1 2 4 5 8 )
( 1 2 4 5 8 ) –> ( 1 2 4 5 8 )
( 1 2 4 5 8 ) –> ( 1 2 4 5 8 )
( 1 2 4 5 8 ) –> ( 1 2 4 5 8 )
3. Finding common elements between two arrays
For Intersection of two arrays, print the element only if the element is present in both arrays.
Use two index variables i and j, initial values i = 0, j = 0
If arr1[i] is smaller than arr2[j] then increment i.
If arr1[i] is greater than arr2[j] then increment j.
If both are same then print any of them and increment both i and j.
public static void main(String a[]){
int arr1[] = {1, 2, 4, 5, 6};
int arr2[] = {2, 3, 5, 7};
int i = 0, j = 0;
while (i < arr1.length && j < arr2.length)
if (arr1[i] < arr2[j])
i++;
else if (arr2[j] < arr1[i])
j++;
else
System.out.print(arr2[j++]+" ");
i++;
}
}
Output: 2,5
4. Find the duplicates in an array
We are doing here is to loop over an array Comparing each element to every other element.
For doing this, we are using two loops, inner loop, and outer loop.
We are also making sure that we are ignoring comparing of elements to itself by checking for i
!= j before printing duplicates
Note: The more efficient way of doing this is to use a set.
public static void main(String[] args)
Scanner sc=new Scanner(System.in);
System.out.println("enter size of array");
int n=sc.nextInt();
int arr[]=new int[n];
System.out.println("enter elements");
for(int i=0;i<n;i++){//for reading array
arr[i]=sc.nextInt();
for (int i = 0; i < arr.length; i++)
{
for (int j = i + 1 ; j < arr.length; j++)
if (arr[i]==(arr[j]))
// got the duplicate element
System.out.println(arr[i]);
enter size of array
enter elements
12 32 21 21 34 67 93 34
o/p is:
21
34
Using concept of a Set
Note: The more efficient way of doing this is to use a set.
All you need to know is that Set as it name suggests doesn't allow duplicates in Java.
Which means if you have added an element into Set and try to insert duplicate element again
there will only be a single instance of the element?
This can be done by using HashSet class. In the solution, we iterate over the elements, insert
them into HashSet using add() method and check return value.
If add() returns false it means that element is not allowed in the Set and that is your duplicate.
Here is the code sample to do this :
Set set = new HashSet<>(); //from java utils
for(int i=0;i<n;i++){//for reading array
if (set.add(arr[i]) == false)
System.out.println("duplicate element in array : " + arr[i]);
}
Output : enter size of array
enter elements
1 12 12 34 56 78
duplicate element in array : 12
5. Find the pair of numbers in the array whose sum is equal to a given number.
We need to find a pair of numbers if they exists given that their sum should be a required number
Here we find that by “For every element in the array. Add every other element to it and check the
Sum”
The sumPair fucntion takes in an array the number which is the sum as input.
Functions/methods are those which does a repetetive task in a class. They can also be used for
improving modularity of the code
public static void main(String[] args)
Scanner sc=new Scanner(System.in);
System.out.println("enter number of elements");
int n=sc.nextInt();
int arr[]=new int[n];
System.out.println("enter elements");
for(int i=0;i<n;i++){//for reading array
arr[i]=sc.nextInt();
}
System.out.println("pairs of numbers with given sum are “);
sumPair(arr, 10);
static void sumPair(int arrayInput[], int sumNumber) {
for (int i = 0; i < arrayInput.length; i++) {
for (int j = i + 1; j < arrayInput.length; j++) {
if (arrayInput[i] + arrayInput[j] == sumNumber) {
System.out.println(arrayInput[i] + " , " + arrayInput[j] );
output:
enter number of elements in array
enter elements
345678
pairs of numbers in array with sum 10 are :
3,7
4,6.
NOTE: There can be a better way to do this by avoiding nested loops (Hint: Set and Subraction)
SQL Basic Questions with Answers
SQL stands for Structured Query Language. It is a language used to interact with the database,
i.e to create a database, to create a table in the database, to retrieve data or update a table in the
database etc.
This article attempts to cover the basic questions that can be asked in an interview on this topic,
Firstly, there are 4 types of SQL statements,
1. DLL(Data Definition Language): which deals with database schemas and descriptions, of how
the data should reside in the database.
Ex: Create, Alter etc.
2. DML(Data Manipulation Language): which deals with data manipulation, and includes most
common SQL statements such SELECT, INSERT, UPDATE, DELETE etc, and it is used to store,
modify, retrieve, delete and update data in the database.
3. DCL(Data Control Language): which includes commands such as GRANT, and mostly
concerned with rights, permissions and other controls of the database system.
Ex: grant, revoke etc.
4. TCL(Transaction Control Language): which deals with a transaction within a database.
Ex: Commit, rollback etc.
In this article, we will understand few operations that can be done on the single table.
Consider the table below which stores user info of a company with the below structure,
user_id first_name last_name email age
1 bhargav gundu bhargav.gundu@gmail.com 22
2 ajinkya ingale ajinka.ingale@yahoo.com 23
3 vivek jhaver vivek.jhaver@gmail.com 24
4 anshul chaturvedi anshul.chaturvedi@gmail.com 30
5 rajesh shou rajesh.shou@yahoo.com 25
6 sai teja sai.teja@gmail.com 27
Now, we can do a variety of operations on this table.
DML:
1. Create a table like in the figure shown above.
Ans: CREATE TABLE Users ( user_id INT NOT NULL, first_name VARCHAR(25) NOT
NULL, last_name VARCHAR(25) NOT NULL, email VARCHAR(80) NOT NULL, age INT
NOT NULL, PRIMARY KEY (user_id))
Here Users is the table name. INT and VARCHAR are the data types and others are column names.
PRIMARY_KEY indicates that user_id is the unique value used to reference any row in the above
table.
2. Alter the table created above to add users city.
Ans: alter table Users add column city varchar(10) after age;
In alter command we have to define the column name its type and the position of the column by
after keyword.
Let's learn few DML commands now.
1. Select all the users present in the database.
This is the most common question and no brownie points for guessing the answer :)
Ans: Select * from users;
Here '*' indicates select all the columns from the table.
2. Select only ages and first names of all the users.
Ans: Select first_name, age from users;
3. Now, the number of users in the database could be in order of millions, hence a more practical
question would be 'Print any n users from the database'
Ans: we can use limit function available for this use case, which just limits the no of rows in o/p
select * from users limit n; ( n could be 10,20 etc)
4. How do you give me all users aged 30 and above?
Ans: For this, we can use the WHERE clause
select * from users where age>30; (Think if age 30 users are printed or not? )
5. What if is ask you print all users in my database who are teenagers?
Ans: We have 2 ways to do this, let's look at both:
a. Select * from users where age>=13 and age<=19;
Now this AND acts as a boolean And which translates to true only if both the conditions are true
b. One more handy way of doing this is by using between function
Select * from users where age between 13 and 19;
Please note that between includes both lower and upper limits.
6. What if I want all usernames and their ids with their names in upper case.
Ans: select UPPER(first_name), user_id from users;
We also have LOWER for lower case and INITCAP which only makes the first letter capital.
7. What if I want all users whose first name whose name contains 'bhargav' ?
Ans: we can use regex functions like 'LIKE'
select * from users where first_name LIKE '%bhargav%' ;
here % means there can be any character before and after the given keyword.
The above query we used could be used like 'what if i want to know how many users in my database
use yahoo?'
select * from users where email like '%yahoo%';
We can also only modify things while printing like
8. what if I want to print name like firstname_last_name?
Ans: we can use CONCAT function which essentially joins two string values
select concat(FIRST_NAME,'_',LAST_NAME) from us ers;
SQL - Joins
JOIN is one of the heavily used concept across SQL and a question on Joins is almost compulsory in any
interview, this blog aims to equip you basic knowledge of join to help you in interview questions.
JOIN is used to combine records from multiple tables.
Lets take this example:
Lets say we have two tables Users which has user specific data like name, address etc and Orders
has order related details like quantity ,bill etc.
We separate the data and store them in separate tables, to satisfy the normal forms we discussed
in previous blog
Customers table:
Customer ID Customer_Name City Country
Orders Table :
Order ID Customer ID Quantity Order Date
Now, if i want to print, CustomerID, Customer_name, city and OrderIDs placed by him how would
you do it? The answer is using JOIN.
a JOIN clause is used to return a table that merges the contents of two or more other tables together.
For example, if we had two tables — one containing information on Customers and another
containing information on the Orders of students — we could use a JOIN clause to bring them
together to create a new table: a complete list of Customers and their Orders.
Now, there are many types of joins,
(INNER) JOIN: Returns records that have matching values in both tables
LEFT (OUTER) JOIN: Return all records from the left table, and the matched records from the right table
RIGHT (OUTER) JOIN: Return all records from the right table, and the matched records from the left table
FULL (OUTER) JOIN: Return all records when there is a match in either left or right table
Lets understand each one of them with an example:
First lets define two tables for ilustration purpose, lets fill some data in the tables we defined
previously:
Customers:
Customer ID Customer Name City Country
1 Ajay Hyderabad India
2 Balaji Vizag India
3 Charan Mumbai India
Orders:
Order ID Customer ID Quantity Order Date
10308 2 7 1996-09-18
10309 2 3 1996-09-19
10310 3 8 1996-09-20
Inner Join:
Below figure represents the Inner join in Venn diagram, in true sense, Inner join is intersection of
the two tables
Now, to perform left join we can use,
SELECT Orders.OrderID, Customers.CustomerName
FROM Orders
INNER JOIN Customers ON Orders.CustomerID = Customers.CustomerID;
INNER JOIN keyword selects all rows from both tables as long as there is a match between the
columns. If there are records in the "Orders" table that do not have matches in "Customers", these
orders will not be shown!
Hence the o/p will be :
10308 Balaji
10309 Balaji
10310 Charan
As you can see, customer Id 1 is not included as he didnt place any order
Left Join:
The LEFT JOIN keyword returns all records from the left table (table1), and the matched records
from the right table (table2). The result is NULL from the right side, if there is no match(look at
the picture below)
SELECT Customers.CustomerName, Orders.OrderID
FROM Customers
LEFT JOIN Orders ON Customers.CustomerID = Orders.CustomerID
ORDER BY Customers. Customer Name;
hence the o/p will be:
+---------------+---------+
| Customer_name | OrderID |
+---------------+---------+
| Ajay | NULL |
| Balaj | 10308 |
| Chara | 10309 |
| Chara | 10310 |
+---------------+---------+
You can see the null value for customer Ajay as he didn't place any order
Right Join:
The RIGHT JOIN keyword returns all records from the right table (table2), and the matched
records from the left table (table1). The result is NULL from the left side, when there is no match.
SELECT Customers.CustomerName, Orders.OrderID
FROM Customers
RIGHT JOIN Orders ON Customers.CustomerID = Orders.CustomerID
ORDER BY Customers.CustomerName;
hence the o/p will be:
+---------------+---------+
| Customer_name | OrderID |
+---------------+---------+
| Balaj | 10308 |
| Chara | 10309 |
| Chara | 10310 |
+---------------+---------+
Full Join or Full Outer Join:
The FULL OUTER JOIN keyword return all records when there is a match in either left (table1)
or right (table2) table records.
SELECT Customers.CustomerName, Orders.OrderID
FROM Customers
FULL OUTER JOIN Orders ON Customers.CustomerID = Orders.CustomerID
ORDER BY Customers.CustomerName;
Check the related blogs below
Basic SQL Interview Questions and Answers
SQL - Aggregate Functions and Examples
Aggregate functions in SQL are used to perform the calculation on data. These functions are inbuilt in
SQL and return a single value.
SQL Aggregate Functions Usage:
Generally from a business perspective, Top levels managers are usually interested in knowing
whole figures and not necessary the individual details.
>Aggregate functions allow us to easily produce summarized data from our database.
For instance, say from a 'sales' database, management may require following reports
Least sold product variants.
Most sold product variants.
Average number that each product is sold in a month.
Take a Free Campus Placement Mock Test
We easily produce above reports using aggregate functions.
The ISO standard defines five (5) aggregate functions namely;
1) COUNT
2) SUM
3) AVG
4) MIN
5) MAX
In any interview, on SQL topic, you can expect atleast one question from the aggregate functions,
so lets first understand each of them and then look at few examples
1) The COUNT function returns the total number of values in the specified field. It works on both
numeric and non-numeric data types. All aggregate functions by default exclude nulls values
before working on the data.
2) MySQL SUM function which returns the sum of all the values in the specified column. SUM
works on numeric fields only. Null values are excluded from the result returned.
3) MySQL AVG function returns the average of the values in a specified column. Just like the
SUM function, it works only on numeric data types.
4) The MIN function returns the smallest value in the specified table field.
5) Just as the name suggests, the MAX function is the opposite of the MIN function. It returns the
largest value from the specified table field.
Consider an orders table with the following structure.
OrderID OrderDate OrderPrice OrderQuantity CustomerName
1 12/22/2005 160 2 Smith
2 08/10/2005 190 2 Johnson
3 07/13/2005 500 5 Baldwin
4 07/15/2005 420 2 Smith
5 12/22/2005 1000 4 Wood
6 10/2/2005 820 4 Smith
7 11/03/2005 2000 2 Baldwin
Now, based on the above concepts there can be many types of questions like:
1. Count the number of orders made by a customer with CustomerName Smith made.
SELECT COUNT (*) FROM Sales WHERE CustomerName = 'Smith
2. In the above we used a filter condition, question could also be like, what is the count of total no
of orders, for that we can simply use,
SELECT COUNT(*) FROM Sales
3.What if we are interested in the total value of all the orders?
We can use, SELECT SUM(OrderPrice) FROM Sales
4. More detailed analysis could be like, what is the average number of items per order?
We can use, SELECT AVG(OrderQuantity) FROM Sales
Note, we can combine all the above results with filters, what if I need average order price when
the price is more than 200.
SELECT AVG(OrderPrice) FROM Sales WHERE OrderPrice > 200
5.minimum price paid for any of the orders
SELECT MIN(OrderPrice) FROM Sales
6. maximum paid for any of the orders
SELECT MAX(OrderPrice) FROM Sales
This was a brief intro into aggregate functions. All the very best.
44 common campus interview questions!
1) How do you do? How are you feeling now?
2) Tell me about yourself?
3) What do you know about our company?
4) Why do you want to work in our company?
5) Are you nervous?
6) How do you compensate your lack of experience?
7) What have you done in the last six months to prepare for this interview?
8) What projects have you done?
9) Why should I hire you?
10) What is today's significance?
11) What's your career objective?
12) Why is that your academic performance has gradually come down?
13) Why IT industry?
14) How much salary are you expecting?
15) Where do you want to see yourself five years from now?
16) What are your short-term, mid-term and long-term goals?
17) Which one will you select: TCS or Infosys?
18) What's your stand on the Uri attack?
19) What's your stand on the upcoming presidential elections in the U.S?
20) What are the three things that you always want to change in yourself?
21) What are your strengths and weakness?
22) Tell me something about yourself that is not in your resume?
23) What are your hobbies?
24) What are your interests?
25) Who is your role model and why?
26) What are the three things that you don't like in your college?
27) If you were given a chance, then what are the few things that would you like to change in
your college?
28) What are your future plans?
29) Why not further studies?
30) When was the last time you were appreciated in your college for any activity that you have
done?
31) Can you relocate?
32) Can you sign a bond with us?
33) How many hours can you work in a day?
34) Which is more important: Personal life or Professional life?
35) What do you like the most and the least about working in the IT industry?
36) If you were an interviewer, then how do you hire?
37) What makes you nervous or uncomfortable?
38) Tell me about a time when you resolved a problem?
39) Tell me about a time when you disagreed with someone?
40) Why do you need a job?
41) Do you believe in the concept called dream job?
42) Tell me about a time when you have experienced regret?
43) What are your areas of interests?
44) Do you have any questions for me/us?