XII SQL Practical Notes 2024-25
XII SQL Practical Notes 2024-25
CLASS XII
PRACTICAL NOTES
1. Create the following table named "Charity" and write SQL queries for the tasks
that follow:
Table : Charity
P_ID LastName FirstName Address City Contribution
1 Bindra Jaspeet 5B, Gomti Nagar Lucknow 3500.50
2 Rana Monica 21 A, Bandra Mumbai 2768.00
3 Singh Jatinder 8, Punjabi Bagh Delhi 2000.50
4 Arora Satinder K/1,Shere Mumbai 1900.00
Punjab Colony
5 Krishnan Vineeta A-75,Adarsh
Nagar
i) Display all first names in lowercase.
ii) Display all last names of people of Mumbai city in uppercase.
iii) Display Person Id along with First 3 characters of his/her name.
iv) Display first name concatenated with last name for all the employees.
v) Display length of address along with Person ID.
vi) Display last 2 characters of City and Person ID.
vii) Display Last Names and First names of people who have "at" in the
second or third position in their first names.
viii) Display the position of ‘a’ in Last name in every row.
ix) Display Last Name and First name of people who have "a" as the last
character in their First names.
x) Display the first name and last name concatenated after removing the
leading and trailing blanks.
xi) Display Person Id, last names and contribution rounded to the nearest
rupee of all the persons.
xii) Display Person Id, last name and contribution with decimal digits
truncated of all the persons.
xiii) Display Last name, contribution and a third column which has
contribution divided by 10. Round it to two decimal points.
Ans. SQL command to creating table “Charity”-
CREATE TABLE CHARITY
(
P_ID int Primary Key,
LastName varchar(30),
FirstName varchar(30),
Address varchar(50),
City varchar(20),
Contribution decimal(10,2)
);
XII IP Practical Notes 2024-25
xi) Display Person Id, last names and contribution rounded to the nearest rupee of
all the persons.
SELECT P_ID, LastName, ROUND(Contribution,-3) FROM Charity;
xii) Display Person Id, last name and contribution with decimal digits truncated of
all the persons.
SELECT P_ID, LastName, TRUNCATE(Contribution,0) FROM Charity;
xiii) Display Last name, contribution and a third column which hascontribution
divided by 10. Round it to two decimal points.
SELECT P_ID, LastName, Contribution,
ROUND((Contribution/10),2) FROM Charity;
2. Consider the table "Grocery" and write SQL queries for the tasks that follow:
Table: Grocery
i)Display Item name, unit price along with Date of purchase for all the
Items.
ii) Display Item name along with Month (in number) when it was purchased
for all the items.
iii) Display Item name along with year in which it was purchased for all the
items.
iv) Display Item Id, Date of Purchase and day name of week (e.g. Monday) on
which it was purchased for all the items.
v) Display names of all the items that were purchased on Mondays or
Tuesdays.
vi) Display the day name of the week on which Rice was purchased.
vii) Display the Item name and unit price truncated to integer value (no
decimal digits)of all the items.
viii) Display current date
Ans. SQL command to creating table “Grocery”-
i) Display Item name, unit price along with Date of purchase for all the Items.
SELECT ItemName, UnitPrice, Date_Purchase FROM Grocery;
ii) Display Item name along with Month (in number) when it was purchased for all
the items.
SELECT ItemName, Month(Date_Purchase) FROM Grocery;
iii) Display Item name along with year in which it was purchased for all the items.
SELECT ItemName, YEAR(Date_Purchase) FROM Grocery;
iv) Display Item Id, Date of Purchase and day name of week (e.g. Monday) on which
it was purchased for all the items.
SELECT ItemName, Date_Purchase, Dayname(Date_Purchase) FROM Grocery;
v) Display names of all the items that were purchased on Mondays or Tuesdays.
SELECT * FROM Grocery
WHERE Dayname(Date_Purchase) IN („Monday‟,‟Tuesday‟);
vi) Display the day name of the week on which Rice was purchased.
SELECT ItemName, dayname(Date_Purchase) FROM Grocery
WHERE ItemName like „Rice‟;
vii) Display the Item name and unit price truncated to integer value (no decimal
digits) of all the items.
SELECT ItemName, Truncate(UnitPrice) FROM Grocery;
# MAX() – MAX() function is used to find the Highest Value of any column or any
expression based on a column. MAX() takes one argument which can be any
column name or a valid expression involving a column name.
a) To find the highest cost of any type of shoe in the factory.
SELECT MAX(cost)FROM shoes;
# MIN() – MIN() function is used to find the Lowest Value of any column or an
expression based on a column. MIN() takes one argument which can be any
column name or a valid expression involving a column name.
c) To find the lowest cost of any type of shoe in the factory.
SELECT MIN(cost)FROM shoes;
# AVG() – AVG() function is used to find the average value of any column or an
expression based on a column. AVG() takes one argument which can be any
column name or a valid expression involving a column name.
Limitation:The argument of AVG() function can be of numeric (int /
decimal) type only.Averages of String and Date type data are not defined.
e) To find the average margin from shoes table.
SELECT AVG(margin)FROM shoes;
f) To find the average quantity in stock for the shoes of type Sports.
SELECT AVG(qty)FROM shoes WHERE type=„sports‟;
g) To find the average quantity in stock for the shoes of type Sports.
SELECT AVG(qty) FROM shoes WHERE type = 'Sports';
# SUM() – SUM() function is used to find the Total Value of any column or an
expression based on a column. SUM() also takes one argument which can be any
column name or a valid expression involving a column name.
Like AVG(), the argument of SUM() function can be of numeric (int/decimal)
type only. Sums of String and Date type data are not defined.
h) To find the total quantity present in the stock.
SELECT SUM(qty)FROM shoes;
i) To find the total value (Quantity X Cost) of Shoes of type 'Office' present in the
inventory.
SELECT SUM(cost*qty)FROM shoes WHERE type = 'Office';
n) The management of the shoe factory may want to know what is the total quantity
of shoes of various types. i.e., what is the total quantity of shoes of type School,
Office, and Sports each.
SELECT type, SUM(qty) FROM shoes GROUP BY type;
o) The management may also want to know what is the maximum, minimum, and
average margin of each type of shoes.
SELECT type, MIN(margin), MAX(margin), AVG(margin)
FROM shoes GROUP BY type;
q) The management of the shoe factory may want to know which shoes total
quantityis more than 1500.
SELECT type, SUM(qty) FROM shoes
GROUP BY type HAVING SUM(qty) > 1500;
Note :In these statements if we try to put the condition using WHERE instead of
HAVING, we shall get an error.
r) The management of the shoe factory may want to know what is the totalquantity of
shoes, of sizes other than 6, of various types. i.e., what is the totalquantity of shoes
(of sizes other than 6) of type School, Office, and Sports each. Moreover, the report
is required only for those groups for which the totalquantity is more than 1500.
SELECT type, SUM(qty) FROM shoes
WHERE size <>6 ->Checks individual row
GROUP BY type HAVING sum (qty) > 1500; ->Checks individual group
s) The management may also want to know what is the maximum, minimum,
andaverage margin of each type of shoes. But in this reports shoes of sizes 6 and
7only should be included. Report is required only for those groups for which
theminimum margin is more than 2.
SELECT type, MIN(margin), MAX(margin), AVG(margin) FROM shoes
WHERE size in (6,7)
GROUP BY type having MIN(margin) > 2;
t) The management of the shoe factory wants a report of orders which lists three
columns: Order_No, corresponding customer name, and phone number
SELECT order_no , name, phone
FROM orders, customers
WHERE orders.cust_code = customers.cust_code;
Or,
SELECT order_no , name, phone
FROM orders X, customers Y
WHERE X.cust_code = Y.cust_code;
Output :
v) The management wants the names of customers who have placed any order of
quantity more than 300.
SELECT name, address FROM orders, customers
WHERE orders.cust_code = customers.cust_code
and order_qty > 300;
Output :
w) The management wants a report in which with each Order_No management needs
name of the corresponding customer and also the total cost (Order quantity X Cost
of the shoe) of the order are shown.
SELECT order_no, Order_Qty, customers.name,
cost*order_qty AS 'Order Cost'
PREPARED BY TAPOSH KARMAKARPGT P a g e 10 | 23
AIR FORCE SCHOOL JORHAT |MOBILE : 7002070313
XII IP Practical Notes 2024-25
Table : SPORTS
a) Based on these tables write SQL statements for the following queries:
i. Display the lowest and the highest classes from the table STUDENTS.
Ans. SELECT MIN(CLASS), MAX(CLASS) FROM STUDENTS
ii. Display the number of students in each class from the table STUDENTS.
Ans. SELECT CLASS, COUNT(CLASS) FROM STUDENTS
GROUP BY CLASS;
Output:
+-------+--------------+
| CLASS | COUNT(CLASS) |
+-------+--------------+
| 10 | 4 |
| 11 | 3 |
| 12 | 3 |
+-------+--------------+
iii. Display the number of students in class 10.
Ans. SELECT CLASS, COUNT(CLASS) FROM STUDENTS
GROUP BY CLASS HAVING CLASS=10;
Output:
+-------+--------------+
| CLASS | COUNT(CLASS) |
+-------+--------------+
| 10 | 4 |
+-------+--------------+
iv. Display details of the students of Cricket team.
Ans. SELECT X.*, Y.GAME FROM STUDENTS X, SPORTS Y
WHERE X.AdmNo=Y.AdmNo AND Y.Game LIKE „Cricket‟;
Output:
+-------+---------------+-------+-----+-----+------------------------+------------------+---------+
| AdmNo | Name | Class | Sec | RNo | Address | Phone | GAME |
+-------+---------------+-------+-----+-----+------------------------+------------------+---------+
| 1324 | Naresh Sharma | 10 | A | 1 | 31, Mohan Nagar | 435654 | Cricket |
| 1461 | David DSouza | 11 | B | 1 | D-34, Model Town | 243554, 98787665 | Cricket |
| 1434 | Varuna | 12 | B | 21 | 69, Rohini | | Cricket |
| 2328 | Peter Jones | 10 | A | 18 | 21/32B, Vishal Enclave | 24356154 | Cricket |
+-------+---------------+-------+-----+-----+------------------------+------------------+---------+
v. Display the Admission number, name, class, section, and roll number of
thestudents whose grade in Sports table is 'A'.
b) Predict the output of each of the following SQL statements, and then verify the
output by actually entering these statements:
i. SELECT class, sec, count(*) FROM students GROUP BY class,
sec;
Ans. +-------+-----+----------+
| class | sec | count(*) |
+-------+-----+----------+
| 10 | A | 3 |
| 10 | B | 1 |
| 11 | B | 2 |
| 11 | C | 1 |
| 12 | B | 1 |
| 12 | C | 2 |
+-------+-----+----------+
ii. SELECT Game, COUNT(*) FROM Sports GROUP BY Game;
Ans. +-------------+----------+
| Game | COUNT(*) |
+-------------+----------+
| Basket Ball | 5 |
| Cricket | 4 |
| Volleball | 2 |
+-------------+----------+
iii. SELECT game, name, address FROM students, Sports
WHERE students.admno = sports.admno AND grade = 'A';
Ans. +-------------+----------------+------------------------+
| game | name | address |
+-------------+----------------+------------------------+
| Cricket | Naresh Sharma | 31, Mohan Nagar |
| Volleball | Subya Akhtar | 12, Janak Puri |
| Basket Ball | Peter Jones | 21/32B, Vishal Enclave |
| Basket Ball | Mohini Mehta | 37, Raja Garden |
| Basket Ball | Utkarsh Madaan | C-32, Punjabi Bagh |
| Cricket | Varuna | 69, Rohini |
+-------------+----------------+------------------------+
iv. SELECT Game FROM students, Sports
WHERE students.admno = sports.admno
AND Students.AdmNo = 1434;
Ans. +-------------+
| Game |
+-------------+
| Basket Ball |
| Cricket |
+-------------+
CARSHOWROOM DATABASE
Create a database called CARSHOWROOM has the following four relations:
INVENTORY: Stores name, price, model, year of manufacturing, and fuel
type for each car in inventory of the showroom,
CUSTOMER: Stores customer Id, name, address, phone number and
email for each customer,
SALE: Stores the invoice number, car Id, customer id, sale date, mode of
payment, sales person‟s employee Id, and selling price of the car sold,
EMPLOYEE: Stores employee Id, name, date of birth, date of joining,
designation, and salary of each employee in the showroom.
Table :INVENTORY
Field Type Null Default Comments
CarID varchar(4) No
CarName varchar(15) No
Price float No
Model varchar(10) No
YearManufacture int(11) No
Fueltype varchar(10) No
Table :CUSTOMER
Field Type Null Default Comments
CustId varchar(5) No
CustName varchar(20) No
CustAdd varchar(30) No
Phone varchar(10) No
Email varchar(20) No
Table :SALE
Field Type Null Default Comments
InvoiceNo varchar(6) No
CarId varchar(5) No
CustId varchar(5) No
SaleDate date No
PaymentMode varchar(20) No
EmpID varchar(5) No
SalePrice float No
Table :EMPLOYEE
Field Type Null Default Comments
EmpID varchar(5) No
EmpName varchar(20) No
DOB date No
DOJ date No
Designation varchar(12) No
Salary int(11) No
1. In order to increase sales, suppose the car dealer decides to offer his customers
to pay the total amount in 10 easy EMIs (equal monthly installments). Assume
that EMIs are required to be in multiples of 10,000. For that, the dealer wants
to list the CarID and Price along with the following data from the Inventory
table:
a) Calculate GST as 12% of Price and display the result after rounding it off to
one decimal place.
SELECT ROUND(12/100*Price,1) "GST" FROM INVENTORY;
+---------+
| GST |
+---------+
| 69913.6 |
| 80773.4 |
| 68043.7 |
| 77743.0 |
| 42624.6 |
| 78589.7 |
| 61680.0 |
| 73680.0 |
+---------+
b) Add a new column FinalPrice to the table inventory, which will have the
value as sum of Price and 12% of the GST.
ALTER TABLE INVENTORY ADD(FinalPrice Numeric(10,1));
UPDATE INVENTORY SET FinalPrice=Price+Round(Price*12/100,1);
SELECT * FROM INVENTORY;
+-------+---------+--------+-----------+-----------------+----------+------------+
| CarID | CarName | Price | Model | YearManufacture | Fueltype | FinalPrice |
+-------+---------+--------+-----------+-----------------+----------+------------+
| D001 | Car1 | 582613 | LXI | 2017 | Petrol | 652526.6 |
| D002 | Car1 | 673112 | VXI | 2018 | Petrol | 753885.4 |
| B001 | Car1 | 567031 | Sigma1.2 | 2019 | Petrol | 635074.7 |
| B002 | Car2 | 647858 | Delta1.2 | 2018 | Petrol | 725601.0 |
| E001 | Car3 | 355205 | 5 STR STD | 2017 | CNG | 397829.6 |
| E002 | Car3 | 654914 | CARE | 2018 | CNG | 733503.7 |
| S001 | Car4 | 514000 | LXI | 2017 | Petrol | 575680.0 |
| S002 | Car4 | 614000 | VXI | 2018 | Petrol | 687680.0 |
+-------+---------+--------+-----------+-----------------+----------+------------+
c) Calculate and display the amount to be paid each month (in multiples of
1000) which is to be calculated after dividing the FinalPrice of the car into 10
instalments. After dividing the amount into EMIs, find out the remaining
amount to be paid immediately, by performing modular division.
SELECT CarId, FinalPrice,
ROUND((FinalPrice- MOD(FinalPrice,10000))/10,0) "EMI",
MOD(FinalPrice,10000) "Remaining Amount" FROM INVENTORY;
+-------+------------+-------+------------------+
| CarId | FinalPrice | EMI | Remaining Amount |
+-------+------------+-------+------------------+
| D001 | 652526.6 | 65000 | 2526.6 |
| D002 | 753885.4 | 75000 | 3885.4 |
| B001 | 635074.7 | 63000 | 5074.7 |
| B002 | 725601.0 | 72000 | 5601.0 |
| E001 | 397829.6 | 39000 | 7829.6 |
| E002 | 733503.7 | 73000 | 3503.7 |
| S001 | 575680.0 | 57000 | 5680.0 |
| S002 | 687680.0 | 68000 | 7680.0 |
+-------+------------+-------+------------------+
2. a) Add a new column Commission to the SALE table. The column Commission
should have a total length of 7 in which 2 decimal places to be there.
ALTER TABLE SALE ADD(Commission Numeric(7,2));
b) Calculate commission for sales agents as 12 per cent of the SalePrice, insert
the valuesto the newly added column Commission and then display records
of the table SALE where commission > 73000.
UPDATE SALE SET Commission=12/100*SalePrice;
SELECT * FROM SALE WHERE Commission > 73000;
+-----------+-------+--------+------------+--------------+-------+-----------+------------+
| InvoiceNo | CarId | CustId | SaleDate | PaymentMode | EmpID | SalePrice | Commission |
+-----------+-------+--------+------------+--------------+-------+-----------+------------+
| I00001 | D001 | C0001 | 2019-01-24 | Credit Card | E004 | 613247 | 73589.64 |
| I00004 | D002 | C0001 | 2018-10-15 | Bank Finance | E007 | 659982 | 79197.84 |
| I00006 | S002 | C0002 | 2019-01-30 | Bank Finance | E007 | 620214 | 74425.68 |
+-----------+-------+--------+------------+--------------+-------+-----------+------------+
3. a) Display customer name in lower case and customer email in upper case from
table CUSTOMER.
SELECT LOWER(CustName), UPPER(Email) FROM CUSTOMER;
+-----------------+---------------------+
| LOWER(CustName) | UPPER(Email) |
+-----------------+---------------------+
| amitsaha | [email protected] |
| rehnuma | [email protected] |
| charvinayyar | [email protected] |
| gurpreet | [email protected] |
+-----------------+---------------------+
b) Display the length of the email and part of the email from the email ID
before the character „@‟. Note – Do not print „@‟.
SELECT LENGTH(Email), LEFT(Email, INSTR(Email, "@")-1)
FROM CUSTOMER;
+---------------+----------------------------------+
| LENGTH(Email) | LEFT(Email, INSTR(Email, "@")-1) |
+---------------+----------------------------------+
| 19 | amitsaha2 |
| 19 | rehnuma |
| 19 | charvi123 |
| 19 | gur_singh |
+---------------+----------------------------------+
c) Let us assume that four digit area code is reflected in the mobile number
starting from position number 3. For example, 1851 is the area code of
mobile number 9818511338. Now, write the SQL query to display the area
code of the customer living in Rohini.
SELECT MID(Phone,3,4) FROM CUSTOMER
WHERE CustAdd like “%Rohini%”;
+----------------+
| MID(Phone,3,4) |
+----------------+
| 1163 |
+----------------+
d) Display emails after removing the domain name extension “.com” from
emails of the customers.
SELECT TRIM(“.com” from Email) FROM CUSTOMER;
+-------------------------+
| TRIM(".com" from Email) |
+-------------------------+
| amitsaha2@gmail |
| rehnuma@hotmail |
| charvi123@yahoo |
| gur_singh@yahoo |
+-------------------------+
f) Using the table INVENTORY, Convert the CarMake to uppercase if its value
starts with the letter „B‟.
g) Using the table INVENTORY, If the length of the car‟s model is greater than
4 then fetch the substring starting from position 3 till the end fromattribute
Model.
SELECT MODEL, LENGTH(MODEL), SUBSTR(MODEL,3)
FROM INVENTORY WHERE LENGTH(MODEL)>4;
+-----------+---------------+-----------------+
| MODEL | LENGTH(MODEL) | SUBSTR(MODEL,3) |
+-----------+---------------+-----------------+
| Sigma1.2 | 8 | gma1.2 |
| Delta1.2 | 8 | lta1.2 |
| 5 STR STD | 9 | STR STD |
+-----------+---------------+-----------------+
h) Using the table EMPLOYEE, Display employee name and the last 2
characters of his EmpId.
SELECT CONCAT(EMPNAME,RIGHT(EMPID,2)) FROM EMPLOYEE;
+--------------------------------+
| CONCAT(EMPNAME,RIGHT(EMPID,2)) |
+--------------------------------+
| Rushil01 |
| Sanjay02 |
| Zohar03 |
| Arpit04 |
| Sanjucta06 |
| Mayank07 |
| Rajkumar10 |
+--------------------------------+
i) Using the table EMPLOYEE, Display designation of employee and the
position of character „e‟ in designation, if present.
SELECT DESIGNATION, INSTR(DESIGNATION,'E') FROM EMPLOYEE;
+--------------+------------------------+
| DESIGNATION | INSTR(DESIGNATION,'E') |
+--------------+------------------------+
| Salesman | 4 |
| Salesman | 4 |
| Peon | 2 |
| Salesman | 4 |
| Receptionist | 2 |
| Salesman | 4 |
| Salesman | 4 |
+--------------+------------------------+
4. a) Using the table EMPLOYEE, Select the day, month number and year of
joining of all employees.
SELECT DAY(DOJ), MONTH(DOJ), YEAR(DOJ) FROM EMPLOYEE;
+----------+------------+-----------+
| DAY(DOJ) | MONTH(DOJ) | YEAR(DOJ) |
+----------+------------+-----------+
| 12 | 12 | 2017 |
| 5 | 6 | 2016 |
| 8 | 1 | 1999 |
| 2 | 12 | 2010 |
| 1 | 7 | 2012 |
| 1 | 1 | 2017 |
| 23 | 10 | 2013 |
+----------+------------+-----------+
b) If the date of joining is not a Sunday, then display it in the following format
"Wednesday, 26, November, 1979."
SELECT DAYNAME(DOJ), DAY(DOJ),MONTHNAME(DOJ), YEAR(DOJ)
FROM EMPLOYEE WHEREDAYNAME(DOJ)!='Sunday';
+--------------+----------+----------------+-----------+
| DAYNAME(DOJ) | DAY(DOJ) | MONTHNAME(DOJ) | YEAR(DOJ) |
+--------------+----------+----------------+-----------+
| Tuesday | 12 | December | 2017 |
| Friday | 8 | January | 1999 |
| Thursday | 2 | December | 2010 |
| Wednesday | 23 | October | 2013 |
+--------------+----------+----------------+-----------+
c) Display the day of birth for all employees whose salary is more than 25000.
SELECT EMPNAME, DAYNAME(DOB), SALARY FROM EMPLOYEE
WHERE SALARY>25000;
+----------+--------------+--------+
| EMPNAME | DAYNAME(DOB) | SALARY |
+----------+--------------+--------+
| Rushil | Sunday | 25550 |
| Sanjay | Monday | 33100 |
| Arpit | Tuesday | 39100 |
| Sanjucta | Sunday | 27350 |
| Mayank | Saturday | 27352 |
| Rajkumar | Thursday | 31111 |
+----------+--------------+--------+
5. a) Display the total number of records from table INVENTORY having a model
as VXI.
SELECT COUNT(*) FROM INVENTORY WHERE Model=”VXI”;
+----------+
| COUNT(*) |
+----------+
| 2 |
+----------+
b) Display the total number of different types of Models available from table
INVENTORY.
SELECT COUNT(DISTINCT Model) FROM INVENTORY;
+-----------------------+
| COUNT(DISTINCT Model) |
+-----------------------+
| 6 |
+-----------------------+
c) Display the average price of all the cars with Model LXI from table
INVENTORY.
SELECT AVG(Price) FROM INVENTORY WHEREModel="LXI";
+------------+
| AVG(Price) |
+------------+
| 548306.5 |
+------------+
d) Find sum of Sale Price of the cars purchased by the customer having ID
C0001 from table SALE.
SELECT SUM(SALEPRICE) FROM SALE WHERE CUSTID=‟C0001‟;
OR,
SELECT SUM(SALEPRICE) FROM SALE GROUP BY CUSTID HAVING
CUSTID=‟C0001‟;
+----------------+
| SUM(SALEPRICE) |
+----------------+
| 1273229 |
+----------------+
6. a) Display the number of cars purchased by each customer from the SALE
table.
SELECT CustID, COUNT(*) "Number of Cars" FROM SALE
GROUP BY CustID;
+--------+----------------+
| CustID | Number of Cars |
+--------+----------------+
| C0001 | 2 |
| C0002 | 2 |
| C0003 | 1 |
| C0004 | 1 |
+--------+----------------+
b) Display the customer Id and number of cars purchased if the customer
purchased more than 1 car from SALE table.
SELECT CustID, COUNT(*) FROM SALE
GROUP BY CustID HAVING Count(*)>1;
+--------+----------+
| CustID | COUNT(*) |
+--------+----------+
| C0001 | 2 |
| C0002 | 2 |
+--------+----------+
c) Display the number of people in each category ofpayment mode from the
table SALE.
SELECT PaymentMode, COUNT(PaymentMode) FROM SALE
GROUP BY Paymentmode ORDER BY Paymentmode;
+--------------+--------------------+
| PaymentMode | COUNT(PaymentMode) |
+--------------+--------------------+
| Bank Finance | 2 |
| Cheque | 1 |
| Credit Card | 2 |
| Online | 1 |
+--------------+--------------------+
d) Display the PaymentMode and number of payments made using that mode
more than once.
SELECT PaymentMode, Count(PaymentMode) FROM SALE
GROUP BY Paymentmode HAVING COUNT(*)>1 ORDER BY Paymentmode;
+--------------+--------------------+
| PaymentMode | Count(PaymentMode) |
+--------------+--------------------+
| Bank Finance | 2 |
| Credit Card | 2 |
+--------------+--------------------+
7.