ByteBoard Notes Notes

To display girls who scored 75 or more

Informatics Practices XI · Experiment 29 of 36 · SQL

11-IPSQL queries
Expt. No.29
Page No.58

Girls with 75 or more

Aim

To display the names and marks of girls who scored 75 or more.

Concepts used

Queries

USE school;SELECT name, marks FROM student WHERE gender = 'F' AND marks >= 75;

A marked line continues the line above it. In your file, write it on the same line.

Table used

Table: student
+-----+-------+---------+--------+--------+------------+-------+
| rno | class | section | gender | name   | dob        | marks |
+-----+-------+---------+--------+--------+------------+-------+
|   1 | XI    | A       | F      | Aarohi | 2009-03-14 |    78 |
|   2 | XI    | A       | M      | Bharat | 2008-11-02 |    45 |
|   3 | XI    | B       | M      | Chetan | 2009-07-21 |  NULL |
|   4 | XI    | B       | F      | Divya  | 2009-01-30 |    91 |
|   5 | XII   | A       | M      | Eshan  | 2008-05-17 |    66 |
|   6 | XII   | A       | F      | Fatima | 2008-09-09 |    83 |
|   7 | XII   | B       | M      | Gagan  | 2007-12-25 |    38 |
|   8 | XII   | B       | F      | Hina   | 2008-02-11 |  NULL |
|   9 | XI    | A       | M      | Ishan  | 2009-10-05 |    57 |
|  10 | XII   | A       | F      | Jaya   | 2008-06-28 |    74 |
+-----+-------+---------+--------+--------+------------+-------+

Output

mysql> USE school; Database changed
mysql> SELECT name, marks FROM student WHERE gender = 'F' AND marks >= 75; +--------+-------+ | name | marks | +--------+-------+ | Aarohi | 78 | | Divya | 91 | | Fatima | 83 | +--------+-------+ 3 rows in set

✓ Printed by running this query set, not typed by hand.

Result

Three girls scored 75 or more: Aarohi (78), Divya (91) and Fatima (83). Jaya (74) just missed, and Hina's marks are NULL.

Viva voce: what the examiner may ask

01What is the difference between > and >=?

>= also includes the value itself, so 75 would be shown.

02Why is 'F' in quotes?

gender is a CHAR column, so its values are text.

03Would gender = 'f' also work?

In MySQL, yes; text comparison ignores case by default.

Variations for the lab test

  1. Display boys who scored below 50.
  2. Display girls of class XI.
  3. Display students whose marks are between 70 and 80 and who are girls.
! Common mistake Writing marks => 75 gives a syntax error; the operator is >=.
Back to the 11-IP index