used in HAVING clause. Example . . .
- import sqlite3 connection = sqlite3.connect("Academy.db") cursor = connection.cursor() cursor.execute("SELECT GENDER,COUNT(GENDER) FROM Student GROUP BY GENDER HAVING COUNT(GENDER)> ") result = cursor.fetchall() co = [i[ ] for i in cursor.description] print(co) print(result) OUTPUT ['gender', 'COUNT(GENDER)'] [('M', )] The SQL AND, OR and NOT Operators . The WHERE clause can be combined with AND, OR, and NOT operators. The AND and OR operators are used to filter records based on more than one condition. In this example you are going to display the details of students who have scored other than ‘A’ or ‘B’ from the “student table” 12th Computer Chapter - - Data Manipulation Through SQL Example for WHERE WITH NOT Operator Example .
- import sqlite3 connection = sqlite3.connect("Academy.db") cursor = connection.cursor() cursor.execute("SELECT * FROM student where NOT Grade='A' and NOT Grade='B'") result = cursor.fetchall() print(*result,sep="\n") OUTPUT ( , 'BASKAR', 'C', 'M', . , ' - - ') ( , 'TARUN', 'D', 'M', . , ' - - ') Example for WHERE WITH AND Operator In this example we are going to display the name, Rollno and Average of students who have scored an average between to % (both limits are inclusive) Example . - import sqlite3 connection = sqlite3.connect("Academy.db") cursor = connection.cursor() cursor.execute("SELECT Rollno, Sname, Average FROM student WHERE (Average>= AND Average<= )") result = cursor.fetchall() print(*result,sep="\n") OUTPUT ( , 'Akshay', .
) ( , 'VARUN', . ) Example for WHERE WITH OR Operator In this example we are going to display the Rollno and name of students who have not scored an average between to % 12th Computer Chapter - - Example . - import sqlite3 connection = sqlite3.connect("Academy.db") cursor = connection.cursor() cursor.execute("SELECT Rollno, Sname FROM student WHERE (Average< OR Average> )") result = cursor.fetchall() print(*result,sep="\n") OUTPUT ( , 'Akshay') ( , 'Aravind') ( , 'BASKAR') ( , 'SAJINI') ( , 'VARUN') ( , 'PRIYA') Querying A Date Column . In this example we are going to display the rollno, name and grade of students who have born in the year Example .
- import sqlite3 connection = sqlite3.connect("Academy.db") cursor = connection.cursor() cursor.execute("SELECT Rollno, Sname, grade FROM student WHERE( >=' - - ' AND <=' - - ')") result = cursor.fetchall()