0% found this document useful (0 votes)
4 views2 pages

Set 1 - SQL - Ip

The document contains a Python script that connects to a MySQL database and creates a table named 'admissions' with various student-related fields. It also includes SQL commands to insert data into the table and perform several queries, such as selecting specific columns, aggregating data, and formatting results. The script demonstrates basic database operations including table creation, data insertion, and data retrieval using SQL syntax.

Uploaded by

8201ayush
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

Set 1 - SQL - Ip

The document contains a Python script that connects to a MySQL database and creates a table named 'admissions' with various student-related fields. It also includes SQL commands to insert data into the table and perform several queries, such as selecting specific columns, aggregating data, and formatting results. The script demonstrates basic database operations including table creation, data insertion, and data retrieval using SQL syntax.

Uploaded by

8201ayush
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

import mysql.

connector
mydb=mysql.connector.connect(host="localhost", user="root", passwd = "a",
database="practical")
mycursor=mydb.cursor()

sql =
"
CREATE TABLE admissions
(admno INT(4) PRIMARY KEY,
studName CHAR(15),
admDate DATE,
fees INT(5),
Sub CHAR(10),
attendance FLOAT
);

mycursor.execute(sql)
mydb.commit()

INSERT INTO admissions VALUES (1, 'Jigar', '2021-04-02', 1500, 'IP', 78.15698);
INSERT INTO admissions VALUES (2, 'Dinesh', '2021-06-15', 2000, 'Hin', 96.72);
INSERT INTO admissions VALUES (3, 'Rishav', '2022-02-01', 1800, 'IP', 85.1335);
INSERT INTO admissions VALUES (4, 'Kinjal', '2022-04-05', 1500, 'IP', 88.0);
INSERT INTO admissions VALUES (5, 'Sonali', '2022-05-02', 1800, 'Hin', 92.00077);

select month (admdate) from admissions where studName = "Sonali"

select count(*), Sub


from admissions
group by sub;

select SUM (fees) from admissions where sub = "IP";

select upper(studName) from admissions;

select round(attendance, 2) from admissions;

mysql> SELECT left(studName,3) FROM admissions;


+------------------+
| left(studName,3) |
+------------------+
| Jig |
| Din |
| Ris |
| Kin |
| Son |
+------------------+
5 rows in set (0.02 sec)

mysql> SELECT studName, fees FROM admissions order by attendance DESC;


+----------+------+
| studName | fees |
+----------+------+
| Dinesh | 2000 |
| Sonali | 1800 |
| Kinjal | 1500 |
| Rishav | 1800 |
| Jigar | 1500 |
+----------+------+
5 rows in set (0.00 sec)

sq

You might also like