All Mock
All Mock
1.
'Display EmployeeId and EmployeeName of those employees where their Company is
�Wipron� or �Datasys�.
The EmployeeId should display only the numeric value of the EmployeeId. for
example e101 should be displayed as 101.'
2.
'Display the Location and number of cabins in each location provided the number of
cabins in that location is more than 2.
For the above example, location �GEC� has 3 cabins and must be included in the
result.'
3.
'Display the CabinId and Location of those cabins which are never allocated to any
employee.
Note: allocated cabin is one that is present in the allocation table.'
4.
'Display EmployeeId and EmployeeName of those employees who have been allocated
with the cabins for more than 10 days.
Do not display duplicate records.
Note: There can be more than 1 row in the allocation table for a given employee
with more than 10 days.
The employee should appear only once in the result.'
5.
'Display AllocationId of those allocations where charge collected is more than the
average charge collected for all the allocations.
For example for the above data, the average charge collected is 3000. So
AllocationId 107 will be one of the roes in the output.
'
SELECT ALLOCATIONID FROM ALLOCATION WHERE CHARGE >
(SELECT AVG(CHARGE) FROM ALLOCATION)
6.
'For each company display the Company name and total number of employees of that
company who are allocated with a cabin.'
7.
'Display the CabinId and Location of the cabin which has been allocated for maximum
number of times.'
8.
'Display the CabinId, EmployeeId, EmployeeName and NoOfDays for which the same
AllocatorId appears more than twice in the allocation table.
For example, AllocatorId A101 appears 3 times in the allocation table. So the
following row will be part of the output:'
9.
'Display the AllocatorId and AllocatorName of the allocators who have allocated
different cabins to the same employee.
Write the query using JOIN concept.'
10.
'Identify the Allocator who allocates the same cabin to different employees.
Display the CabinId, AllocationId, EmployeeId and AllocatorId for the identified
cabins.'
'**********************************************************************************
************************************************
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
###################################################################################
################################################
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$'
A.
'Display the numeric part of giftid as �GIFTNUM� (column alias),
giftname and reduction in price per quantity rounded to the nearest whole number
as
�PRICEREDUCTION� (column alias) of the �Utilities� category gifts.'
B.
'Display customerid and giftid of the giftorders which are been ordered for the
gifts of the category other than the �Home Decor�.
For the given sample data, following records will feature as part of the output
along with other record(s).'
C.
'Display giftid and orderid as �ORDERS� (column alias) of all the gifts that are
been shipped to �Mysore� city.
Display �NA� in ORDERS for the gifts that are not been shipped to �Mysore� and
also for the unordered gifts.'
D.
'Display giftid, giftname, availability and number of times the order placed as
�NOOFORDERS� (column alias)
for those gifts that are available more than 40 units and has been ordered twice
or more times.'
E.
'Display orderid as �ORDERNUM� (column alias) and customerid as �CUSTOMER� (column
alias)
for all the orders as well as for all the customers. Display �N� in CUSTOMER for
customers
who do not belong to �Bangalore� and �NA� in ORDERNUM if the order is not placed
or if the
order is placed by the customers who do not belong to �Bangalore�.'
F.
'Display orderid, customerid and giftid for those giftorders that are been placed
by the same customer
for the �Home Decor� category gifts. For the given sample data, following record
will feature as part
of the output along with other record(s).'
G.
'Identify the customer who has paid the highest total billamount. Display the
customerid, customername
and highest total billamount as �TOTALBILL� (column alias). TOTALBILL has to be
rounded to the
nearest whole number. Billamount can be calculated using price, discount and
quantity.'
SELECT C.CUSTOMERID,C.CUSTOMERNAME,ROUND(SUM(G1.QUANTITY*G.PRICE*(1-
G.DISCOUNT/100))) "TOTALBILL"
FROM CUSTOMER1 C INNER JOIN GIFTORDER G1 ON C.CUSTOMERID=G1.CUSTOMERID INNER JOIN
GIFT G ON
G1.GIFTID=G.GIFTID GROUP BY C.CUSTOMERID,C.CUSTOMERNAME HAVING
SUM(G1.QUANTITY*G.PRICE*(1-G.DISCOUNT/100))=
(SELECT MAX(SUM(G1.QUANTITY*G.PRICE*(1-G.DISCOUNT/100))) "TOTALBILL"
FROM CUSTOMER1 C INNER JOIN GIFTORDER G1 ON C.CUSTOMERID=G1.CUSTOMERID INNER JOIN
GIFT G ON
G1.GIFTID=G.GIFTID GROUP BY C.CUSTOMERID,C.CUSTOMERNAME)
H.
'Identify the giftorders that are been placed by the customers from �Delhi� for the
gifts other than �Showpiece�
category and are been shipped to �Chennai� city. Display orderid, giftid and
customerid for the identified giftorder.'
'**********************************************************************************
************************************************
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
###################################################################################
################################################
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$'
A.
'Display the customerid, name and email of customers whose mobile number has the
number �2� as the third digit.
The customerid should only display the numeric part. It is known that the
customerid follows a standard pattern of
�C� followed any number of digits.(Example, for customerid C003, display 003). '
B.
'Display customerid of all the customers who have done booking multiple times.
For Example customer �C004� has done multiple bookings.'
C.
'Display the customerid of the customers who have booked a train from Surat or to
Surat.
For Example, for the given sample data, customerid �C004� would be one of the rows
in the
output along with other rows.'
SELECT T.TRAINID,T.SOURCE,T.DESTINATION,
CASE TO_CHAR(T.STOPS)
WHEN '0' THEN 'NON-STOP'
ELSE TO_CHAR(T.STOPS)
END STOPS
FROM TRAIN T INNER JOIN TRAIN T1 ON T.TRAINID=T1.TRAINID WHERE
T.DESTINATION=T1.DESTINATION
E.
'For each trainid, display total number of bookings done and total number of quota
seats(ac+nonac)
whether or not a booking was made for the train.'
F.
'Display the customerid, bookingid and trainid for the customers who have booked a
round trip. '
G.
'Display the trainid and total amount of the train that has the second highest
total amount.
For example, for the given sample data, the trainid that has the second highest
total amount
is AA303 and the total amount is 8500.'
'**********************************************************************************
************************************************
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
###################################################################################
################################################
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$'
1.
'Display ToyId, ToyName, Stock of those toys whose stock lies within 10 and 15(both
inclusive)
and toyname contains more than 6 characters.'
2.
'Identify and display CustId, CustName, CustType of those customers whose name ends
with �y�.
For the selected records, if the customer type is NULL display CustType as �N�.
Do case insensitive comparison.'
3.
'Display CustName and total transaction cost as TotalPurchase for those customers
whose
total transaction cost is greater than 1000.'
4.
'For each customer display transactionid, customerid and cost of the transaction
that has the maximum cost among all transactions made by that customer.'
5.
'List all the toyid, total quantity purchased as 'total quantity' irrespective of
the customer.
Toys that have not been sold should also appear in the result with total units as
0'
6.
'List all the ToyId, ToyName, Price of those toys which have the same price'
'**********************************************************************************
************************************************
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
###################################################################################
################################################
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$'
A.
SELECT CUSTOMERID,CUSTNAME,AMOUNTSPENT FROM CUSTOMER
WHERE LOWER(CUSTNAME) LIKE '%i%'
AND DOB BETWEEN ('01-Nov-1982') AND ('31-DEC-1988')
B.
SELECT CUSTNAME||'-'||CUSTOMERID CUSTDETAILS,CONTACTNO,GENDER
FROM CUSTOMER WHERE CUSTOMERID NOT IN (SELECT CUSTOMERID FROM CREDITCARD) AND
GENDER='M'
C.
SELECT CUSTOMERID,SUM(CREDITLIMIT) "TOTAL CREDIT LIMIT" FROM CREDITCARD GROUP BY
CUSTOMERID
HAVING SUM(CREDITLIMIT)>(SELECT AVG(CREDITLIMIT) FROM CREDITCARD)
D.
SELECT C.CUSTOMERID,T.TRANSACTIONID FROM CREDITCARD C
INNER JOIN TRANSACTION T ON C.CARDNO=T.CARDNO
INNER JOIN TRANSACTION T1 ON T.TAMOUNT=T1.TAMOUNT
WHERE T.TRANSACTIONID<>T1.TRANSACTIONID
E.
SELECT C.CUSTOMERID,NVL(TO_CHAR(CR.CARDNO),'NA')
CARDOWNED,NVL(TO_CHAR(T.TAMOUNT),'NT') AMOUNT
FROM CUSTOMER C LEFT JOIN CREDITCARD CR ON C.CUSTOMERID=CR.CUSTOMERID
LEFT JOIN TRANSACTION T ON CR.CARDNO=T.CARDNO
F.
SELECT CUSTOMERID,CUSTNAME FROM CUSTOMER WHERE CUSTOMERID IN
(SELECT CUSTOMERID FROM CREDITCARD GROUP BY CUSTOMERID HAVING COUNT(CARDTYPE)=3)
G.
SELECT C.CUSTOMERID,C.CUSTNAME FROM CUSTOMER C
INNER JOIN CREDITCARD CR ON C.CUSTOMERID=CR.CUSTOMERID
WHERE CR.CARDTYPE IN
(SELECT CARDTYPE FROM CREDITCARD WHERE CARDNO IN
(SELECT CARDNO FROM TRANSACTION GROUP BY CARDNO HAVING COUNT(CARDNO) IN
(SELECT MAX(COUNT(CARDNO)) FROM TRANSACTION GROUP BY CARDNO)))
H.
SELECT CUSTOMERID FROM CUSTOMER
WHERE CUSTOMERID IN
(SELECT CUSTOMERID FROM CREDITCARD WHERE CARDNO IN
(SELECT CARDNO FROM TRANSACTION) AND CARDTYPE='Platinum') AND GENDER='M'